WPML Hooks API
WPML offers filter and action hooks that can be used in your WordPress theme or plugin to provide correct multilingual support. Browse the Hooks Reference API for details of each hook
WPML Shortcodes
WPML provides shortcodes that you can use in both the content and your PHP code. They are listed on the WPML Shortcodes page.
WPML Constants
WPML provides constants defined by the WPML core plugin and our add-on plugins. You can use them in your theme or plugin’s PHP files and templates. For a complete list, see our page about WPML constants.
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 Language switcher style.
Loading of the stylesheet and javascript files for language switcher style depends on the chosen switcher. If you do not need them in your theme, you can tell WPML not to load these files.
These files are located in the following folder:
../wp-content/plugins/sitepress-multilingual-cms/templates/language-switchers/YOUR_CHOSEN_LANGUAGE_SWITCHER_THEME/
To do 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 | style.css?ver=1 |
ICL_DONT_LOAD_LANGUAGES_JS | script.js?ver=1 |
To set these constants, define them in the theme’s functions.php file. For example:
define('ICL_DONT_LOAD_NAVIGATION_CSS', true);
Disabling Critical Communications with Translations Services For Test Sites
As part of the regular workflow for developing websites, you may need to duplicate your production site and work on a different location or a staging environment. This is common practice and entirely recommended. However, this separate testing site would by default connect to the translation service exactly like the main, production site. This can create inconsistencies in the main’s site communications with the translation service.
Here is a typical example, to help illustrate this issue:
- Your testing site fetches a completed translation from the translation service.
- The translation service marks these items as “delivered”.
- You cannot anymore fetch these delivered translations on your production site.
To avoid issues like this, we recommend “telling” WPML that a staging site is for testing purpose only. You can do that by adding the following line to your site’s wp-config.php site:
define( 'WPML_ENVIRONMENT', 'test' );
Note: This will block only critical requests, but most of the requests will still be available. For example, the list of translation services will display as usual.