- availability:
-
WPML Version: 3.9.3
- description:
-
Enables the possibility to save a different value per language for your theme/plugin options using WPML language switcher on directly the settings screen.
- type:
- action
- category:
- Inserting Content
- parameters:
-
do_action( 'wpml_multilingual_options', $wp_option_name );
$wp_option_name
(Required) Exact option name as it is stored in wp_options table database.
- hook example usage:
-
Let’s say that you need to assign a different value per language (translate) for a theme option, this usually is easily achievable with the help of WPML String Translation.
However, you may need to act differently with some themes and add a different value directly from the theme options panel. For example, with Avada you can do.
Now, you are working with a theme where you need to translate your options with this later approach, for example your footer option theme_footer. For this, you would need to:
- Add a value for your footer option at Theme Options > Footer,
- Add the following code on your functions.php file and queue it as early as possible:
add_action( 'init', 'my_theme_bootstrap' ); function my_theme_bootstrap(){ do_action( 'wpml_multilingual_options', 'theme_footer' ); $settings = get_option( 'theme_footer'); // [...] }
- Go back to your Theme Options > Footer.
- Click on the language switcher placed on the top bar and switch languages.
- Add a new different value for it.
- You should keep a different value per language.
- If you visit the front-end, it should display a different value for the option.
- If you check the database, there should be a new value stored in wp_options table as theme_footer_fr, where _fr is the language suffix.