WordPress Shortcodes provide a convenient way to create complex content in the WordPress post editor. In addition, you can use shortcodes in PHP files by using the do_shortcode() function.

The following shortcodes are available for WPML since the version 3.2.

wpml_language_selector_widget

  • Display WPML’s drop-down language switcher.
  • This is similar to the wpml_add_language_selector hook.
  • To customize the output of this shortcode, go to the WPML -> Languages page and use the settings in the Custom language switcher section.
  • Display WPML’s horizontal language switcher.
  • The output of this shortcode is exactly the same as for the wpml_footer_language_selector hook.
  • To customize the output of this shortcode, go to the WPML -> Languages page and use the settings in the Footer language switcher section.

wpml_language_form_field

  • Make a custom search form multilingual-ready.
  • The output of this shortcode is exactly the same as for the wpml_add_language_form_field hook.

wpml-string

  • Example: [wpml-string context="my-domain" name="my-name"]My string[/wpml-string]
  • Register and translate a string. This shortcode requires the plugin WPML String Translation to be active.
  • To translate this string, go to the WPML -> String Translation page and use the following info (replacing the names with your own):
    • Domain: my-domain
    • Name: my-name
    • String: My string
  • Please note that in order for the strings to be registered and available for translation, you first need to visit the pages that feature them, on the front-end.

wpml_language_switcher

  • This shortcode is available since WPML 3.6.0 version.
  • Example: [wpml_language_switcher type="footer" flags=1 native=1 translated=1][/wpml_language_switcher]
  • Arguments:
    • 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.
  • 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.