Skip Navigation
availability:

WPML Version: 3.7.0

description:

Displays the language selector as configured on the WPML -> Languages page.

type:
action
category:
Site-Wide Language Information
parameters:
do_action( 'wpml_language_switcher', $args, $twig_template_string );

This action hook has two optional parameters and works as a {{wpml_language_switcher}} shortcode.

$args

(array) (Optional) Arguments to filter the language switcher output

  • type – Define the language switcher type – footer, post_translations, widget or custom (default).
  • flags (alias for display_flags) – Use 1 to display flags and 0 not to.
  • link_current (alias for display_link_for_current_lang ) – Use 1 to display flags and 0 not to.
  • native (alias for display_names_in_native_lang ) – Use 1 to display flags and 0 not to.
  • translated (alias for display_names_in_current_lang ) – Use 1 to display flags and 0 not to.
  • template – The template slug if it needs to be overwritten. Otherwise it will be defined by the type .
  • For the type, WPML will use the settings on the WPML -> Languages page, from the related sections except for widgets, which will take the default settings for a widget language switcher.
  • We can also pass a Twig template as the content of the shortcode, as shown in the example below. If the Twig template is not valid, the shortcode will not render anything.
  • $twig_template_string

    (string) (Optional)  a Twig template string

    hook example usage:

    Add the code below to your theme template files, where you want the language switcher to be displayed at.

    Example

    do_action( 'wpml_language_switcher', $args, $twig_template_string );

    If you prefer, you can also add the above code line in a PHP widget like PHP Text Widget.