- availability:
-
WPML Version: 4.7.4
- description:
-
Enables the possibility to save a different value per language for your theme/plugin options using the WPML language switcher from the Settings screen.
To set different options per language, you can declare admin strings translatable via the WPML Translation Management. If you want to use a custom integration (like Avada), use the parameters below.
- type:
- action
- category:
- Inserting Content
- parameters:
-
do_action( 'wpml_multilingual_options', $wp_option_name, $wp_options_screen_ids);
$wp_option_name
(Required) Exact option name as it is stored in wp_options table database.
$wp_options_screen_ids
(Optional) Lists admin screen IDs where options are managed.
- hook example usage:
-
To translate your footer option theme_footer:
- Identify the screen ID for your Theme Options page.
- Add a value for your footer option at Theme Options → Footer.
- Add the following code to your functions.php file and queue it as early as possible:
- Go back to your Theme Options → Footer.
- Switch languages using the language switcher on the top bar—let’s say you switch to French (_fr).
- Add a new different value for the option.
Example
add_action( 'init', 'my_theme_bootstrap' ); function my_theme_bootstrap(){ $screen_ids = ['theme-options-screen-id']; do_action( 'wpml_multilingual_options', 'theme_footer' $screen_ids); $settings = get_option( 'theme_footer'); // [...] }
If you visit the frontend, it should display the different value. If you check the database, there should be a new value stored in the wp_options table as theme_footer_fr, where _fr is the language suffix.