### Load and Configure WPML Installer Bootstrap Source: https://wpml.org/documentation/support/embedded-installer-authors Include the Installer bootstrap file and configure its setup before the init hook. This example shows how to set installation tab visibility, affiliate ID, affiliate key, and source information for coupons. ```php require_once 'vendor/autoload.php'; include 'vendor/otgs/installer/loader.php'; $wp_installer_instance = null; WP_Installer_Setup( $wp_installer_instance, [ 'plugins_install_tab' => 1, // optional, default value: 0 'affiliate_id:wpml' => '99999', // optional, default value: empty 'affiliate_key:wpml' => 'NNNNNNNNNN', // optional, default value: empty 'src_name' => 'NAME OF THEME', // optional, default value: empty, needed for coupons 'src_author' => '', // optional, default value: empty, needed for coupons ] ); ``` -------------------------------- ### Custom Admin Installer Tab Configuration Source: https://wpml.org/documentation/support/embedded-installer-authors Example of how to register a custom tab in the theme options to display WPML installation options. This code should be called after the 'admin_init' hook. ```php echo '
'; $config['template'] = 'compact'; //required $config['product_name'] = 'WPML'; $config['box_title'] = 'Multilingual GoodDay'; $config['name'] = 'GoodDay'; //name of theme/plugin $config['box_description'] = 'GoodDay theme is fully compatible with WPML - the WordPress Multilingual plugin. WPML lets you add languages to your existing sites and includes advanced translation management.'; $config['repository'] = 'wpml'; // required $config['package'] = 'wpml'; // required $config['product'] = 'multilingual-cms-2'; // required WP_Installer_Show_Products($config); echo "
"; ``` -------------------------------- ### Install WPML Installer via Composer Source: https://wpml.org/documentation/support/embedded-installer-authors Add the WPML Installer as a dependency to your theme or plugin using Composer. ```bash composer require otgs/installer ``` -------------------------------- ### Complete config.json Example Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/designing-custom-currency-switchers-using-template-files Includes all fields: name, optional CSS, and optional JavaScript. ```json { "name": "My custom Vertical List", "css": ["style.css"], "js": ["script.js"], } ``` -------------------------------- ### Divi Call to Action Module Example Source: https://wpml.org/documentation/support/maintaining-divi-builder-compatibility-wpml This is an example of a Divi Call to Action module's block syntax. It shows the registered name and attributes for the module. ```html ``` -------------------------------- ### Install WooCommerce REST PHP Client Library Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual Install the WooCommerce REST PHP client library using Composer. This library simplifies interaction with the WooCommerce REST API. ```bash composer require automattic/woocommerce ``` -------------------------------- ### Example Response for Post Query Source: https://wpml.org/documentation/related-projects/wpml-graphql This is an example JSON response for the post query, showing language and translation information for each post and its connected items like categories. ```json { "data": { "posts": { "nodes": [ { "slug": "bye-world", "uri": "/2023/05/18/bye-world/", "language": { "code": "en" }, "categories": { "nodes": [ { "name": "End of the day" }, { "name": "Greetings" } ] }, "translations": [ { "slug": "adios-mundo", "uri": "/es/2023/05/18/adios-mundo/", "language": { "code": "es" }, "categories": { "nodes": [ { "name": "Fin del día" }, { "name": "Saludos" } ] } }, { "slug": "tchau-mundo", "uri": "/pt-pt/2023/05/18/tchau-mundo/", "language": { "code": "pt-pt" }, "categories": { "nodes": [ { "name": "Fim do dia" }, { "name": "Saudações" } ] } } ] }, { "slug": "hello-world", "uri": "/2018/07/05/hello-world/", "language": { "code": "en" }, "categories": { "nodes": [ { "name": "Greetings" }, { "name": "Start of the day" } ] }, "translations": [ { "slug": "hola-mundo", "uri": "/es/2018/07/05/hola-mundo/", "language": { "code": "es" }, "categories": { "nodes": [ { "name": "Inicio del día" }, { "name": "Saludos" } ] } }, { "slug": "ola-mundo", "uri": "/pt-pt/2018/07/05/ola-mundo/", "language": { "code": "pt-pt" }, "categories": { "nodes": [ { "name": "Começo do dia" }, { "name": "Saudações" } ] } } ] } ] } } } ``` -------------------------------- ### Query Installed Languages Source: https://wpml.org/documentation/related-projects/wpml-graphql Retrieve data for all installed languages on the site. This query is helpful for building features like language switchers. ```graphql query Languages { languages { code country_flag_url default_locale native_name translated_name url } } ``` -------------------------------- ### Memcached Server Configuration (Example) Source: https://wpml.org/documentation/support/using-wpml-with-memcached-caching An example of the final Memcached server configuration in object-cache.php, specifying the server host and port. This is used to establish a persistent object cache. ```php $memcached_servers = array( 'default' => array( 'memcached:11211' ) ); ``` -------------------------------- ### Equivalent Code for Wildcard Usage Source: https://wpml.org/documentation/support/language-configuration-files/translate-strings-in-wp-options-table This example shows the expanded form of the wildcard usage, explicitly listing all sub-keys that would be included when using '*'. ```xml ``` -------------------------------- ### Example Gutenberg Block with Link Source: https://wpml.org/documentation/support/language-configuration-files/make-custom-gutenberg-blocks-translatable A sample custom Gutenberg block with a clickable link, demonstrating the structure of block attributes that can be made translatable. ```html ``` -------------------------------- ### Example Hreflang Tag for Spanish Version Source: https://wpml.org/documentation/support/adding-hreflang-wordpress This is an example of an hreflang tag indicating a homepage has a version for Spanish users. ```html ``` -------------------------------- ### Example Output of wpml_post_language_details (English) Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This is the expected output when retrieving language details for a post on an English version of the site. ```PHP 'en', 'locale' => 'en_US', 'text_direction' => false, 'display_name' => 'English', 'native_name' => 'English', 'different_language' => false, ); ?> ``` -------------------------------- ### Example Output of wpml_post_language_details (German) Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This is the expected output when retrieving language details for a post on a German version of the site, after translation. ```PHP 'de', 'locale' => 'de_DE', 'text_direction' => false, 'display_name' => 'German', 'native_name' => 'Deutsch', 'different_language' => true, ); ?> ``` -------------------------------- ### Example Gutenberg Block with Translatable Attributes Source: https://wpml.org/documentation/support/language-configuration-files/make-custom-gutenberg-blocks-translatable Illustrates a Gutenberg block's JSON definition, highlighting attributes that can be configured for translation. ```json ``` -------------------------------- ### Registering a Shortcode with Attributes Source: https://wpml.org/documentation/support/language-configuration-files/translate-custom-shortcodes-with-wpml Example of registering a 'goodmorning' shortcode with 'name' and 'type' attributes using WPML's custom XML configuration. ```xml               goodmorning                name         type                ``` -------------------------------- ### Configure Fusion Flip Box Shortcode for Translation Source: https://wpml.org/documentation/support/maintaining-the-fusion-builder-avada-compatibility-with-wpml Example of how to add the fusion_flip_box shortcode and its attributes to the wpml-config.xml file for string extraction and translation. ```xml fusion_flip_box title_front title_back text_front image ``` -------------------------------- ### Initial Re-indexing with WP-CLI Source: https://wpml.org/documentation/related-projects/using-elasticpress-on-your-multilingual-site Use this command to re-index all posts after installing or updating WPML ElasticPress. This process can take several hours for large sites. ```bash wp wpml_elasticpress sync --setup --post-type=post ``` -------------------------------- ### Registering a Shortcode with a Link Attribute Source: https://wpml.org/documentation/support/language-configuration-files/translate-custom-shortcodes-with-wpml Example of registering a 'fanpage' shortcode with a 'link' attribute, including a custom label for the Advanced Translation Editor. ```xml               fanpage                link                ``` -------------------------------- ### Create Post Duplicates Programmatically (Front-end) Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This example shows how to create duplicates of a post when it's inserted from the front-end, using the 'wpml_make_post_duplicates' action hook. ```php add_action('wp_footer', 'my_duplicate_on_insert'); function my_duplicate_on_insert() { // Create post object $my_post = array( 'post_title' => 'My post to insert from the front-end', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => 1, 'post_category' => array(1) ); // Insert the post into the database $post_id = wp_insert_post( $my_post ); if ( $post_id ) { do_action( 'wpml_make_post_duplicates', $post_id ); } } ``` -------------------------------- ### Get Language Code for a Category Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This example shows how to use the 'wpml_element_language_code' filter to retrieve the language code for a specific category. Ensure the 'element_id' and 'element_type' are correctly set in the arguments array. ```php $args = array('element_id' => 10, 'element_type' => 'category'); $my_category_language_code = apply_filters('wpml_element_language_code', null, $args); ``` -------------------------------- ### Get Language Details for a Category Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This example demonstrates using the 'wpml_element_language_details' filter to fetch comprehensive language information, including trid, source language, and current language code, for a given category. ```php $args = array('element_id' => 10, 'element_type' => 'category'); $my_category_language_info = apply_filters('wpml_element_language_details', null, $args); ``` -------------------------------- ### Query Installed Languages Source: https://wpml.org/documentation/related-projects/wpml-graphql Retrieve information about all languages installed on the site or the default language. ```APIDOC ## Query Languages ### Description Retrieves data for all installed languages on the site or information about the default language. ### Method POST (GraphQL Query) ### Endpoint /graphql ### Queries #### `languages` Query Retrieves a list of all registered languages with their associated data. #### `defaultLanguage` Query Retrieves information about the site's default language. ### Request Example (languages query) ```graphql query Languages { languages { code country_flag_url default_locale native_name translated_name url } } ``` ### Response Example (languages query) ```json { "data": { "languages": [ { "code": "en", "country_flag_url": "http://site.com/wp-content/plugins/sitepress-multilingual-cms-release/res/flags/en.svg", "default_locale": "en_US", "native_name": "English", "translated_name": "English", "url": "http://site.com" }, { "code": "es", "country_flag_url": "http://site.com/wp-content/plugins/sitepress-multilingual-cms-release/res/flags/es.svg", "default_locale": "es_ES", "native_name": "Español", "translated_name": "Spanish", "url": "http://site.com/es/" } ] } } ``` ``` -------------------------------- ### wpml_start_string_package_registration Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This action hook should be fired before starting the string package registration. It must be used together with wpml_delete_unused_package_strings, and will allow WPML String Translation to automatically clean up the package strings that are not used anymore. ```APIDOC ## wpml_start_string_package_registration ### Description This action hook should be fired before starting the string package registration. It must be used together with wpml_delete_unused_package_strings, and will allow WPML String Translation to automatically clean up the package strings that are not used anymore. ### Type action ### Parameters #### Action Parameters - **$package** (array) - Required - The package entity. ### Hook Example Usage (No example provided in source) ``` -------------------------------- ### Example URL with xdomain_data Argument Source: https://wpml.org/documentation/getting-started-guide/language-setup/passing-session-data-between-languages-in-domains When WPML is configured to use languages in domains and cookies need synchronization, arguments like `xdomain_data` are appended to language switcher URLs. This argument contains information to set cookies after language switching. ```html sample.es?xdomain_data=LONG_STRING ``` -------------------------------- ### Example of an urlencoded shortcode Source: https://wpml.org/documentation/support/translating-urlencoded-shortcodes This is an example of how an urlencoded shortcode appears in the WordPress Text mode editor, specifically for a progress bar module. ```shortcode [vc_progress_bar values="%5B%7B%22label%22%3A%22Development%20Test%22%2C%22value%22%3A%2290%22%7D%2C%7B%22label%22%3A%22Design%20Test%22%2C%22value%22%3A%2280%22%7D%2C%7B%22label%22%3A%22Marketing%22%2C%22value%22%3A%2270%22%2C%22color%22%3A%22bar_blue%22%7D%5D" title="Progress Bar Title Test" units="%"] ``` -------------------------------- ### Trigger WPML Import with wget Source: https://wpml.org/documentation/related-projects/wpml-export-and-import/automate-wpml-export-and-import-process Example of using wget to trigger the WPML import process via the URL endpoint. This is useful for cron jobs. ```shell wget -q -O - "https://yoursite.com/?wpml_import_trigger=your-strong-secret-key-here" ``` -------------------------------- ### Get Translated Language Name Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Use this filter to get the translated name of a language in another specified language. The languages do not need to be active on the site. ```php apply_filters( 'wpml_translated_language_name', NULL, $lang_code, $display_code ) ``` -------------------------------- ### Example Gutenberg Block with IDs Source: https://wpml.org/documentation/support/language-configuration-files/make-custom-gutenberg-blocks-translatable An example of a Gutenberg block containing an 'ids' attribute and an HTML input field with a 'foo_form_post_ids' name, which can be configured for ID conversion. ```html
``` -------------------------------- ### Create a Product with Translations and Custom Prices Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual Creates a new product, setting its language, and optionally defining custom prices in secondary currencies. Supports category and image associations. ```php $data = [ 'name' => 'English Test Post', 'type' => 'simple', 'regular_price' => '10.00', 'description' => 'This is a Simple English Test Post', 'short_description' => 'This is a Simple English Test Post', 'categories' => [ [ 'id' => 10 ], [ 'id' => 12 ] ], 'images' => [ [ 'src' => 'https://example.com/image-1.png', 'position' => 0 ], [ 'src' => 'https://example.com/image-2.png', 'position' => 1 ] ], 'lang' => 'en', 'custom_prices' => [ 'EUR' => [ 'regular_price' => 1999, 'sale_price' => 1500 ], 'USD' => [ 'regular_price' => 2100, 'sale_price' => 2099 ] ] ]; $product = $woocommerce->post( 'products', $data ); ``` -------------------------------- ### Loading Products using WP_Query with Language Filtering Source: https://wpml.org/documentation/support/making-woocommerce-themes-multilingual-and-multi-currency-ready Instantiate WP_Query with appropriate arguments to fetch products. Ensure that language filtering is implicitly handled by WPML. ```php 'product', 'posts_per_page' => 10, ); $products = new WP_Query( $args ); ?> ``` -------------------------------- ### Display Language Switcher for Subscribers Source: https://wpml.org/documentation/support/sending-emails-with-wpml Use the 'wpml_user_language_switcher' action to display a language selection interface for subscribers. Replace 'mail@example.com' with the actual subscriber's email. ```php do_action( 'wpml_user_language_switcher', array( 'mail' => 'mail@example.com' ) ); ``` -------------------------------- ### Example Hreflang Tags in Head Section Source: https://wpml.org/documentation/support/adding-hreflang-wordpress Hreflang tags are placed in the section of a page to indicate alternate language versions. This example shows tags for Spanish and German versions. ```html … … ``` -------------------------------- ### Configure Fusion Soundcloud Shortcode with Link Attribute Source: https://wpml.org/documentation/support/maintaining-the-fusion-builder-avada-compatibility-with-wpml Example of configuring a shortcode with a link attribute, such as fusion_soundcloud, in the wpml-config.xml file. This allows internal links to point to translated versions. ```xml fusion_soundcloud url ``` -------------------------------- ### Registering Custom Currency Switcher Template Directory in a Plugin Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/designing-custom-currency-switchers-using-template-files Uses the `wcml_cs_directories_to_scan` filter to add a template directory to be scanned by WPML. ```php function myplugin_wcml_cs_dirs_to_scan( $dirs ) { $folder_name = basename( dirname( __FILE__ ) ); $dirs[] = trailingslashit( WP_PLUGIN_DIR ) . $folder_name . '/templates/'; return $dirs; } add_filter( 'wcml_cs_directories_to_scan', 'myplugin_wcml_cs_dirs_to_scan' ); ``` -------------------------------- ### Example of encoded Chinese URL slug Source: https://wpml.org/documentation/getting-started-guide/translating-page-slugs Illustrates how non-ASCII URL slugs are encoded to prevent spammy-looking URLs when copied. This example shows a Chinese URL for '煮饭' (to cook rice) before and after encoding. ```html example.com/煮饭/ → example.com/%E7%85%AE%E9%A5%AD/ ``` -------------------------------- ### Example of a translated Spanish URL slug Source: https://wpml.org/documentation/getting-started-guide/translating-page-slugs Demonstrates how WPML automatically translates page slugs based on the translated title. This example shows a Spanish URL for a page originally titled 'Mixed Berry Smoothie'. ```html smooothy.com/es/receta/batido-de-bayas-mixtas/ ``` -------------------------------- ### Get WPML Element Type Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Filters a WordPress element type to get its WPML database name. Use this to ensure correct identification of post types, taxonomies, or comments within WPML's translation tables. ```php $wpml_element_type = apply_filters( 'wpml_element_type', 'attachment' ); ``` -------------------------------- ### Run WPML Export and Import with WP-CLI Source: https://wpml.org/documentation/related-projects/wpml-export-and-import/how-to-run-wpml-export-and-import-with-wp-cli Use this command to initiate the WPML Export and Import process via WP-CLI. This command helps in connecting imported translations across different languages. ```bash wp wpml import process ``` -------------------------------- ### Get Post or Term Link in Current Language Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Use this filter to get the URL for a post, page, attachment, or taxonomy term in the current language. It allows customization of link text, optional parameters, anchors, and echo behavior. ```php //produces: Hello World! apply_filters( 'wpml_element_link', 1 ); ``` ```php //produces: Custom link text for the sample page apply_filters( 'wpml_element_link', 2, 'page', __( 'Custom link text for the sample page') ); ``` ```php //produces: Sample Page apply_filters( 'wpml_element_link', 2, 'page', '', array( 'category'=>'foo', 'bar'=>'baz' ) ); ``` ```php //produces: Sample Page apply_filters( 'wpml_element_link', 2, 'page', '', '', 'contact' ); ``` ```php //produces: Uncategorized apply_filters( 'wpml_element_link', 1, 'category' ); ``` ```php //produces: Attachment image title apply_filters( 'wpml_element_link', 25, 'attachment', __( 'Attachment image title') ); ``` -------------------------------- ### wpml_setting Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Get the value of a WPML setting. This filter allows retrieval of specific WPML configuration values. ```APIDOC ## wpml_setting ### Description Returns a WPML setting value. ### Parameters #### Filter Parameters - **$default** (mixed|bool) - Required - The value to return if the settings key does not exist. Set to false if not using. - **$key** (string) - Required - The settings name key to return the value of. ### Hook Example Usage ```php // $is_wpml_configured will return TRUE if WPML is fully setup and FALSE if not. $is_wpml_configured = apply_filters( 'wpml_setting', false, 'setup_complete' ); ``` ``` -------------------------------- ### wpml_element_language_code Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Get the language code for a translatable element by querying WPML’s icl_translations database table. ```APIDOC ## wpml_element_language_code ### Description Get the language code for a translatable element by querying WPML’s icl_translations database table. This filter hook retrieves the language code for a translatable element. ### Type filter ### Parameters #### Arguments - **$language_code** (string) (Required) A 2-letter language code. Defaults to null. - **$args** (array) (Required) An array of arguments to be used. - **element_id** (bool) Use term_taxonomy_id for taxonomies, post_id for posts - **element_type** (string) The type of element to check. Can be a post type: post, page, attachment, nav_menu_item, {custom post key} or taxonomy: category, post_tag, nav_menu {custom taxonomy key} ### Hook Example Usage ```php $args = array( 'element_id' => 10, 'element_type' => 'category' ); $my_category_language_code = apply_filters( 'wpml_element_language_code', null, $args ); ``` ``` -------------------------------- ### wcml_before_sync_product_data Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference This action hook runs before WCML syncs product data, such as images, taxonomies, and variations, from original products to their translations. It provides the original product ID, translated product ID, and the target language. ```APIDOC ## wcml_before_sync_product_data ### Description Run actions before WCML syncs data (images, taxonomies, variations, etc) from original products to their translations. This action is called after wcml_before_sync_product. ### Type action ### Parameters #### Parameters - **$original_product_id** (integer) - The ID of original product. - **$translated_product_id** (integer) - The ID of translated product. - **$target_language** (string) - The language code of translated product. ### Hook Example Usage ```php add_action( 'wcml_before_sync_product_data', 'my_custom_action', 10, 3 ); function my_custom_action( $original_product_id, $translated_product_id, $target_language ) { // my custom action } ``` ``` -------------------------------- ### wpml_current_language Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Gets the current display language of the site. This filter returns the language that is currently being displayed to the user. ```APIDOC ## wpml_current_language ### Description Gets the current display language of the site. This filter returns the language that is currently being displayed to the user. ### Parameters #### Filter Parameters - **$empty_value** (mixed) - Required - This is normally the value the filter will be modifying. We are not filtering anything here so set this to NULL. This for the filter function to actually receive the full argument list. ### Hook Example Usage #### A basic example ```php $my_current_lang = apply_filters( 'wpml_current_language', NULL ); ``` #### Creating a shortcode to return the current language ```php function get_language_shortcode() { return apply_filters( 'wpml_current_language', null ); } add_shortcode( 'language', 'get_language_shortcode' ); ``` ``` -------------------------------- ### wcml_price_currency Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference Gets the current currency set on the front-end. This filter is available on the front-end and returns the active currency. ```APIDOC ## wcml_price_currency ### Description Gets the current currency set on the front-end. This filter is available on the front-end. ### Type filter ### Parameters #### Filter Parameters - **empty_value** (mixed) - Required. Normally, this is the value the filter will be modifying. We are not filtering anything here so you should set this to NULL. This argument allows the filter’s function to receive the full list of arguments. ### Hook Example Usage ```php $current_currency = apply_filters('wcml_price_currency', NULL ); ``` ``` -------------------------------- ### Convert Media URL to Current Language Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference This example shows how to use the 'wpml_media_url' filter to convert a media URL to the language of the current context. This is useful for ensuring media assets are displayed in the correct language. ```php // Convert the media URL to the current language. apply_filters('wpml_media_url', 'https://example.com/wp-content/uploads/dog.jpg'); ``` -------------------------------- ### Match All Subfields with Wildcard Source: https://wpml.org/documentation/support/language-configuration-files/custom-fields-translation-options Use a wildcard to match all subfields starting with a specific prefix or all subfields in an array. ```XML ``` ```XML ``` -------------------------------- ### Syncing Content in Batches with WP-CLI Source: https://wpml.org/documentation/related-projects/using-elasticpress-on-your-multilingual-site Syncs all content in batches of 200 items. This can be useful for managing large amounts of content during synchronization. ```bash wp wpml_elasticpress sync --per-page=200 ``` -------------------------------- ### wpml_translated_language_name Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Retrieves the translated name of a language. This filter can be used to get the name of a language in a specific target language. ```APIDOC ## wpml_translated_language_name ### Description Retrieves the translated name of a language. This filter can be used to get the name of a language in a specific target language. ### Parameters #### Filter Parameters - **$language_code** (string) - Required - The language code for which to retrieve the translated name. - **$target_language_code** (string) - Required - The language code of the target language for the translation. ### Hook Example Usage #### A basic example ```php // will return the translation for 'Italian' in Greek echo apply_filters( 'wpml_translated_language_name', NULL, 'it', 'el' ); ``` ``` -------------------------------- ### Get Element Translations Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Retrieves translations for a given element. The result is an array of translations keyed by language code. ```PHP $translations = apply_filters( 'wpml_get_element_translations', NULL, 2, 'post_page' ); var_dump($translations); /** * The result looks like the following * array(2) { ["en"]=> object(stdClass)#1857 (8) { ["translation_id"]=> string(1) "1" ["language_code"]=> string(2) "en" ["element_id"]=> string(1) "2" ["source_language_code"]=> NULL ["element_type"]=> string(9) "post_page" ["original"]=> string(1) "1" ["post_title"]=> string(4) "Home" ["post_status"]=> string(7) "publish" } ["es"]=> object(stdClass)#1856 (8) { ["translation_id"]=> string(3) "141" ["language_code"]=> string(2) "es" ["element_id"]=> string(3) "187" ["source_language_code"]=> string(2) "en" ["element_type"]=> string(9) "post_page" ["original"]=> string(1) "0" ["post_title"]=> string(6) "Inicio" ["post_status"]=> string(7) "publish" } } */ ``` -------------------------------- ### Register Strings for Translation Source: https://wpml.org/documentation/support/string-package-translation Wrap string registration with 'wpml_start_string_package_registration' and 'wpml_delete_unused_package_strings' to manage string updates and removals. The 'title' key is not required in the 'translate' context. ```php $userId = 123; $package = [ 'kind' => FOO_USER_FIELD_PACKAGE_KIND_TITLE, // The "namespace". 'kind_slug' => FOO_USER_FIELD_PACKAGE_KIND_SLUG, // The "namespace" slug. 'name' => $userId, // Can be a string or an integer, but should be unique inside the "kind" namespace. // The 'title' key is not not required in the "translate" context. ]; do_action( 'wpml_start_string_package_registration', $package ); $fooUserFields = get_option( 'otgs_foo_user_fields' ); foreach ( $fooUserFields as $fooUserField ) { $fieldValue = get_user_meta( $userId, $fooUserField, true ); do_action( 'wpml_register_string', $fieldValue, sanitize_key($fooUserField), $package, $fooUserField, 'LINE' ); } do_action( 'wpml_delete_unused_package_strings',$package ); ``` -------------------------------- ### Optional JavaScript Field in config.json Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/designing-custom-currency-switchers-using-template-files Lists JavaScript files to load from the template folder. Use plain JavaScript. ```json "js": ["script.js", "click-handler.js"] ``` -------------------------------- ### WPBakery Tabs Shortcode Configuration Source: https://wpml.org/documentation/support/maintaining-wpbakery-page-builder-compatibility-with-wpml Example of how to add the 'vc_tta_tabs' shortcode and its 'title' attribute to the language configuration file for translation. ```xml vc_tta_tabs title ``` -------------------------------- ### Create a Product as a Translation of Another Source: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual Creates a new product as a translation of an existing product by specifying the 'translation_of' parameter with the parent product's ID. ```php $data = [ 'name' => 'French Test Post', 'type' => 'simple', 'regular_price' => '10.00', 'description' => 'This is a Simple French Test Post', 'short_description' => 'This is a Simple French Test Post', 'lang' => 'fr', 'translation_of' => '23' ]; $product = $woocommerce->post('products', $data); ``` -------------------------------- ### Get translated language name Source: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference Retrieves the translated name of a language. Use this to display language names in a user-friendly format. ```PHP echo apply_filters( 'wpml_translated_language_name', NULL, 'it', 'el' ); ``` -------------------------------- ### Full Re-indexing with WP-CLI Source: https://wpml.org/documentation/related-projects/using-elasticpress-on-your-multilingual-site Deletes all existing indices and re-indexes all content. Use this command when starting fresh or after major changes. ```bash wp wpml_elasticpress sync –setup ```