Skip Navigation
Updated
March 2, 2023

You can add language switchers to custom locations on your site. This includes adding them to your theme files using PHP, or to pages and posts using shortcodes.

Enabling Custom Language Switchers

In order to display a language switcher using a shortcode or PHP, go to WPMLLanguages and check the box to enable Custom Language Switchers.

Enabling the “Custom language switchers” option

Language Switcher Shortcodes

You can also use WPML’s language switcher block to display language switchers throughout your site, including on posts and pages.

You can use one of these two WPML shortcodes to display a language switcher inside posts and pages:

  • [wpml_language_selector_widget]
  • [wpml_language_selector_footer]
Displaying a language switcher with a shortcode

The wpml_language_selector_widget shortcode outputs the language switcher based on the options set in the Custom Language Switchers section in WPMLLanguages.

The wpml_language_selector_footer shortcode outputs the language switcher based on the options set in the Footer language switcher section in WPMLLanguages. You can use this shortcode even if the Show language switcher in footer checkbox is unchecked. 

Language Switchers Using PHP

You can use PHP to add a language switcher to your theme’s PHP template files. To do this, use the following two actions.

  • do_action('wpml_add_language_selector');
  • do_action( 'wpml_footer_language_selector');

The do_action('wpml_add_language_selector'); action outputs the language switcher based on the options set in the Custom Language Switchers section in WPMLLanguages.

The do_action( 'wpml_footer_language_selector'); action outputs the language switcher based on the options set in the Footer language switcher section in WPMLLanguages. You can use this action even if the Show language switcher in footer option is disabled.

You can also use PHP to create custom language switchers. Read more about how to create a custom language switcher.