Skip Navigation

[Resolved] WPML Language switcher shortcode in Layouts

This thread is resolved. Here is a description of the problem and solution.

Problem: I am using WPML, and I would like to include a custom language switcher in a Layout.

Solution:
- Go to WPML > Languages and enable Custom Language Switchers (custom-switchers.png)
- Customize the Language switcher however you want
- Edit the Layout and remove the old language switcher shortcode
- Add this shortcode to a Visual Editor cell:

[wpml_language_selector_widget type="post_translations" flags=1 native=1 translated=0][/wpml_language_selector_widget]

Then you can add some translatable text like this:

[wpml-string context="some-unique-site-context" name="This post is also available in"]This post is also available in:[/wpml-string]

Relevant Documentation:
https://toolset.com/documentation/translating-sites-built-with-toolset/wpml-string-shortcode/

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#630776

Hi,
I am designing a layout for a custom post type.

The layout consists of several custom fields, but it does not have a field ford the normal "content" area.

first question: is this wrong? do I have to have it, even thaough I am not using it?

The main problem I am opening this support question for:
-------------------------------------------------------------------------------------
Since I am not using the "content area", the default WPML language switcher (which says: This article is also available in:..etc" does not show.
Therefore, I approached the WPML team to see if the switcher can be displayed via a shortcode or not.

the details of my question and their response can be found here:
https://wpml.org/forums/topic/shortcode-to-display-this-post-is-also-available-in-etc/

the shortcode is

[wpml_language_switcher type="post_translations" flags=1 native=1 translated=0]' . '[/wpml_language_switcher]

I applied the shortcode they have, but found out that it works only if I pasted it in posts without the layout plugin.
(i.e. if i created a post and pasted the shortcode directly in the content area).
however, if I created a layout and inserted a "visual editor" block and pasted the shortcode in it, it doesn't show anything.

this is not a general problem with all shortcodes, I have other shortcodes that work fine with the "visual editor" block of the WP Layouts plugin. the problem is related only to the wpml language switcher shortcode.

The WPML support member doesn't seem to fully understand the problem, so I thought of reaching out for help from the Toolset Team.

Note: If I inserted a "widget" block in the layout, and added a language switcher widget, it will display properly, however, the widget doesn't suite my layout design. so there is a problem in the shortcode/Layout interaction.

please note that this happens across multiple sites, and the site with the registered WP Toolset suite is a fresh installation with no content, so it's not a conflict between plugins or so.

Since it is one company that created both WPML and Toolset, I believe that there should be a solution to my problem.

can you please investigate and advise a solution?

Thanks in advance.

#631111
custom-switchers.png

Okay try this:
- Go to WPML > Languages and enable Custom Language Switchers (custom-switchers.png)
- Customize the Language switcher however you want
- Edit the Layout and remove the old language switcher shortcode
- Add this shortcode to a Visual Editor cell:

[wpml_language_selector_widget type="post_translations" flags=1 native=1 translated=0][/wpml_language_selector_widget]
#631254

Thanks Christian,

your method works, but it doesn't show the phrase "This post is also available in: " (which also changes according to the language of the post). This is because the widget doesn't have this phrase.

now i can write it manually in the Layout, but how to make it change according to the language?
so when the post is english, it shows "This post is also available in: " and if the post is in Arabic, it shows the phrase in Arabic..etc

thanks

#631542

You can wrap the wpml-string shortcode around any text string to make it translatable in String Translation:

[wpml-string context="some-unique-site-context" name="This post is also available in"]This post is also available in:[/wpml-string]

More information about that here: https://toolset.com/documentation/translating-sites-built-with-toolset/wpml-string-shortcode/