WPML Coding API
WPML offers functions that can be used in your WordPress theme to provide correct support for multilingual themes.
| Function | Purpose | Notes | ||
|---|---|---|---|---|
| do_action(‘icl_language_selector’) | Insert the drop down language selector. | Described in the language setup section of the getting started guide. | ||
| do_action(‘icl_navigation_menu’) | Insert the top navigation menu. | Described in the navitaion section of the getting started guide. | ||
| do_action(‘icl_navigation_breadcrumb’) | Insert the breadcrumbs trail. | |||
| do_action(‘icl_navigation_sidebar’) | Insert the sidebar navigation. | |||
| icl_get_home_url() | Link to the home page in the active language. | Described in the home page link section of the getting started guide. | ||
| icl_get_languages(‘skip_missing=N’) | Used for building custom language selectors. | Described in the custom language switcher section of the getting started guide. | ||
| icl_link_to_element(ID, type, text, arguments, anchor) | Used for creating language dependent links in themes. | Described in the hard coded links section of the getting started guide. | ||
| icl_object_id(ID, type, return_original_if_missing, language_code) | Used for calculating the IDs of objects (usually categories) in the current language. | Described in the language dependent IDs section of the getting started guide. | ||
| icl_register_string(context, name, value) | Registers a string for translation | Described in the guide for translating texts in other plugins and themes. | ||
| icl_unregister_string(context, name) | Removes a string from the translation table | |||
| icl_t(context, name, value) | Gets the translated value of a string. | |||
Language constants
WPML defines the following constants which can be used in the theme:
| Constant | Description | Example |
|---|---|---|
| ICL_LANGUAGE_CODE | Code for the current language | fr |
| ICL_LANGUAGE_NAME | Name of current language, in the current language | Français |
| ICL_LANGUAGE_NAME_EN | Name of the current language name in English | French |
Disabling WPML’s CSS and JS files
WPML comes with its own CSS and JS files that style its navigation and drop-down language switcher.
If you don’t need them in your theme, you can tell WPML not to load these files. Do to that, define the following constants in your theme:
| Constant | The file it disables |
|---|---|
| ICL_DONT_LOAD_NAVIGATION_CSS | Navigation stylesheets – cms-navigation-base.css and cms-navigation.css |
| ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS | Drop-down language selector stylesheet – language-selector.css |
| ICL_DONT_LOAD_LANGUAGES_JS | Drop-down language selector Javascript – sitepress.js |
To set these constants, define them in the theme’s functions.php file. For example:
define('ICL_DONT_LOAD_NAVIGATION_CSS', true);
I suggest you add a function to get the post ID of the translation related to a certain post.
BTW, great plugin.
Hey, thanks for fantastic plugin
I’m trying to get the full language code (en_US, fr_FR …) of current language
I only found the ICL_LANGUAGE_CODE contstant
is there a way to get the full code?
thank you!
WPML uses the short language codes internally. There’s a locale table that maps to the full locale name (language, country).
You can get that value by checking the current locale, not the language name.
hi WPML,
‘m using your plugin to translate my website to english and arabic
my question is : how to remove language description on the header to have just the fag without description ?
You can create your own custom language switcher:
http://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/
On that page, there is an example for language switchers that display only flags. If you need technical help, please use our forum. There are numerous resolved threads about language switchers in different configurations.
if I have this url
href=”"
if I want to change for each language?
how should I do?
It’s really difficult to give technical support over comments. How about starting a thread in our support forum?
Hi,
Thanks, good stuff here.
Are all the pages in this section (WPML Internals) are still valid for the current version?
Sorry for the stupid question but I see comments spanning multiple versions and can’t find ‘Last Updated For Version XYZ’ or a Date.
Appreciate the documentation.
Thanks!
Yes, the documentation is still valid. WPML’s tables and API have stayed the same. I’ll see if there’s anything that we need to add or expand, but we haven’t made changes that break backward compatibility.
Hello ! I have been searching for a day, an answer on the WPML forum, but I can’t find any solution.
The problem is only on the homepage, I have two times the same homepage link (it’s a static page) and the english homepage (www.mr-ginseng.com/en/) redirect to the main french homepage (www.mr-ginseng.com) . French is the basic language.
The point is,e ven on wordpress admin pannel, they don’t suggest me http://www.mr-ginseng.com/en for the translation but http://www.mr-ginseng.com anyway.
Thanks for your help !
PS : I Use Mystique theme and last version of wordress.
Using icl_get_home_url() with a static home page does not work, it only returns a blank page even though the static page is translated.
You should check the page source (where the link is inserted) and see that you’re linking to the correct page. I suggest to start a thread in our support forum, paste the few HTML and PHP lines of code around the icl_get_home_url() call and let our supporters see what’s happening.
$output .= ‘‘;
echo $output;
Well… That didn’t work.
See http://wpml.org/forums/topic/icl_get_home_url-is-incompatible-with-static-home-page/