Skip Navigation

[Resolved] Conditional output: language

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

Problem:
How to display conditional output based on language

Solution:
When you have installed WPML plugin, constant ICL_LANGUAGE_CODE will give you current language code. You can build a custom shortcode that will return you the current language.

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/conditional-output-language/#post-402783

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

This support ticket is created 7 years, 11 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Bart Gybels 7 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#402752

Dear,

I want to do a conditional output for a different language.

I use the WPML-plugin.

So i want to display in a Visual editor for the dutch language:
Dutch text with dutch url

And i want to display in a Visual editor for the english language:
English text with english url

#402783

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I will guide you how you can display language based content.

Using constant ICL_LANGUAGE_CODE you can get the current language code.

Add the following code to your current theme's functions.php file.


add_shortcode('get_wpml_language_code_value', 'func_wpml_language_code_value_func');
function func_wpml_language_code_value_func() {
  $return = ICL_LANGUAGE_CODE;
  return $return;
}

Where:
You should register 'get_wpml_language_code_value' custom shortcode at:
=> Toolset => Settings => Front-end Content => Third-party shortcode arguments section

Use [wpv-conditional] shortcode to display conditional content.

[wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]

display English content

[/wpv-conditional]

[wpv-conditional if="( '[get_wpml_language_code_value]' eq 'fr' )"]

display French content

[/wpv-conditional]

I hope above solution will help you to resolve your issue.

More info:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#402809

Dear,

Thx for your quick reply but when I do:

[php]
[wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]

  • Event
  • Expo
  • Meeting

[/wpv-conditional]
[php]

It doesn't show the text and if i echo ICL_LANGUAGE_CODE it is 'en'.
What am i doing wrong?

PS: I added the code to funtions and added get_wpml_language_code_value to the 3th party shortcode.

#402814

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Strange.

I need to check on your install. Could you please share problem URL?

#403036

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked the following URL:
hidden link

And I can see that [wpv-conditional] shortcode is working and its displaying the menu items.
See the image:
hidden link

#403037

Thx for the solution.
It was a mistake by me that i was looking to the wrong page :).

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.