Multilingual Content Support¶
- Table of contents
- Multilingual Content Support
Add-Meta-Tags can work well along with plugins that add multilingual support to WordPress. Moreover, all the features, which could assist authors with publishing content in multiple languages, have been implemented. However, these features are not suitable for the convenient publishing of translations of the same content. For this purpose, using a multilingual plugin is highly recommended.
Use case scenarios¶
This page contains information that covers two use case scenarios:
- Each post is published in a single language, but multiple languages are used throughout the web site. In this case, the internal Add-Meta-Tags multilingual features are adequate to assist authors with this task.
- Each post is published in multiple languages (translations). In this case, using a full multilingual plugin is highly recommended.
Internal multilingual features¶
Some features, that can assist authors with using multiple languages throughout the web site, while publishing each post in a single language, have been implemented. These features include:
- Setting a locale in the general plugin settings. This locale is used throughout the web site for the front page, content and archives, overriding the locale as returned by WordPress'
get_bloginfo('language')
function. - A metabox feature, named Content locale override, which adds a text input field in the Metadata box in the post editing screen. This field can be used to customize the locale on a per post basis.
- A setting that enables the generation of a HTML link element with the hreflang attribute according to the content's locale.
- A setting that strips the region code from the hreflang attribute so as to prevent it from targeting users in a specific region.
The above settings are not meant to be used and have not been tested with a multilingual plugin. Enabling them when a multilingual plugin is used could lead to unexpected results and is not recommended.
Supported multilingual plugins¶
Add-Meta-Tags does not offer any official statement of guaranteed interoperability with any 3rd party plugins.
However, since v2.8.9, experimental build-in support for some popular plugins has been implemented. Add-Meta-Tags should work with the following multilingual plugins out-of-the-box:
WPML¶
WPML should work out of the box without further configuration for basic use. A language configuration file (wpml-config.xml
) ships with Add-Meta-Tags since 2.8.9.
Polylang¶
Polylang should work out of the box without further configuration for basic use. Polylang uses the same language configuration file as WPML (wpml-config.xml
).
Tech Notes¶
Where Add-Meta-Tags stores its data¶
Add-Meta-Tags uses the documented WordPress API to access and store its settings and data on your WordPress platform. All the plugin settings are stored in a single WordPress option, while all other post specific data, like a custom description, keywords, title, etc, are stored in Custom Fields.
Translatable Add-Meta-Tags Settings¶
Due to the way Add-Meta-Tags stores its settings, creating and delivering translations of them requires some configuration of the multilingual plugin that is used. The Add-Meta-Tags settings that you should consider translating are the following:
- Site Description (
['add_meta_tags_opts']['site_description']
) - Site Keywords (
['add_meta_tags_opts']['site_keywords']
) - Global Keywords (
['add_meta_tags_opts']['global_keywords']
) - Copyright URL (
['add_meta_tags_opts']['copyright_url']
)
Important Note¶
Please note that the above information applies to the generation of metadata on the default WordPress front page (latest posts). If a static page has been set as the front page, then the custom description/keywords are retrieved from the relevant custom fields of that page.
Example of translating settings programmatically¶
Users are encouraged to use each multilingual plugin's API and tools to create or deliver translated versions of the above settings.
However, it is still possible to translate some of the plugin settings programmatically by attaching filtering functions to the following filter hooks and return the translation of the relevant Add-Meta-Tags option:
amt_settings_site_description
amt_settings_site_keywords
amt_settings_global_keywords
amt_settings_copyright_url
The following example attaches a filtering function to the amt_settings_site_keywords
filter hook, and returns the proper translation of the site keywords. The same can be done for the site description and the global keywords by attaching similar filtering functions to the relevant filter hook. X_GET_CURRENT_LANGUAGE()
is a hypothetical API call to your multilingual plugin in order to get the current language.
function amt_get_translated_site_keywords( $default ) {
$lang = X_GET_CURRENT_LANGUAGE();
if ( $lang == 'el-GR' ){
return 'el-keyword1, el-keyword2, el-keyword3';
} elseif ( $lang == 'de-DE' ){
return 'de-keyword1, de-keyword2, de-keyword3';
}
// If there is no match, return the en-US keywords.
return $default;
}
add_filter( 'amt_settings_site_keywords', 'amt_get_global_keywords' );
Translatable Add-Meta-Tags Custom Fields¶
Add-Meta-Tags stores post specific data, like the custom description, custom keywords, custom title, to internal Custom Fields.
Usually, multilingual plugins create a different post object for every translation, so there should be no need for further configuration. In case such configuration is required, the internal custom field names used by this plugin, the contents of which would require translation, are:
_amt_description
- the content's custom description (the HTML form box has the ID:amt_custom_description
)._amt_keywords
- the content's custom keywords (the HTML form box has the ID:amt_custom_keywords
)._amt_title
- the content's custom title (the HTML form box has the ID:amt_custom_title
)._amt_news_keywords
- the content's custom news keywords (the HTML form box has the ID:amt_custom_newskeywords
)._amt_express_review
- the content's review related data (the HTML form box has the ID:amt_custom_express_review
).
Other Multilingual Plugins Currently Being Tested¶
The following multilingual plugins are currently being tested.
babble¶
TODO: Add more details
- Site settings translations: possibly programmatically as shown above
- Custom field translations: supported after adding the following code in
functions.php
or in a custom plugin:
function amt_babble_translation_fields( array $fields, WP_Post $post ) {
$fields['_amt_description'] = new Babble_Meta_Field_Text( $post, '_amt_description', _x('Custom description', 'Add-Meta-Tags meta field', 'babble') );
$fields['_amt_keywords'] = new Babble_Meta_Field_Text( $post, '_amt_keywords', _x('Custom keywords', 'Add-Meta-Tags meta field', 'babble') );
$fields['_amt_title'] = new Babble_Meta_Field_Text( $post, '_amt_title', _x('Custom title', 'Add-Meta-Tags meta field', 'babble') );
$fields['_amt_news_keywords'] = new Babble_Meta_Field_Text( $post, '_amt_news_keywords', _x('Custom news keywords', 'Add-Meta-Tags meta field', 'babble') );
$fields['_amt_express_review'] = new Babble_Meta_Field_Text( $post, '_amt_express_review', _x('Review information', 'Add-Meta-Tags meta field', 'babble') );
return $fields;
}
add_filter( 'bbl_translated_meta_fields', 'amt_babble_translation_fields', 10, 2 );
qTranslate-X¶
WORKS: Possible to translate custom fields in the post editing screen.
DOES NOT WORK: Translation of admin settings in the plugin settings page.
TODO: Add more details
Configuration¶
At Settings->Languages->Custom Integration
- Custom Fields:
amt_custom_description amt_custom_keywords amt_custom_title amt_custom_newskeywords amt_custom_express_review site_description site_keywords global_keywords copyright_url
- Custom admin pages:
options-general.php?page=add-meta-tags-options
If you can help with the configuration of this plugin, please do so at the wordpress.org forums.
- functions.php various
<?php if( $q_config[ 'language' ] == 'en'): ?> something in English <?php endif; ?> <?php if( $q_config[ 'language' ] == 'de'): ?> something in Deutsch <?php endif; ?>