Home » Blog » Tutorials » Howto Display Different Widgets Per Language

Howto Display Different Widgets Per Language

March 29th, 2011 by

WPML lets you translate widget titles and the body of text widgets. Sometimes, it’s not enough and you want to have completely different widgets for each language. I’ll show you how to do this using Widget Logic.

Widget Logic is a plugin that allows controlling where widgets display using PHP code. You can use it to specify where widgets are allowed, including which languages they will display in.

For example, supposing that I want to have different feeds in the widget area. There are different ways to do this, but I’ll show how it can be done using Widget Logic and language conditions.

Before we begin, download and activate Widget Logic:
http://wordpress.org/extend/plugins/widget-logic/

Add multiple copies of the widget to the Widget Area

Each of these widgets will be active in only one language, so we need as many copies as the number of languages we have.

The order of these copies doesn’t matter, as only one will be active at any time.

Two RSS widgets, one per language

Add language conditions per widgets

Click to edit each of these widgets and add the language conditions to the Widget Logic field.

WPML's language code

The logic that we add uses WPML’s language code constant – ICL_LANGUAGE_CODE (reference). For example, for English we add:

ICL_LANGUAGE_CODE == 'en'

This condition tells Widget Code to display this widget only on English pages.

We repeat this for all the copies that we created.

The result – different widgets per language

You should expect to see the different widgets per language now.

English page German page

53 Responses to “Howto Display Different Widgets Per Language”

  1. Antonina says:

    Ok i guess I solved.
    I added the widget twice to the same widget area, then I edited each one to make it display in each language. and it worked!! thanks! anyhow i still did not understand if the String Translation module work forthis issue, and i would like to know now! :)

  2. vladimirK-3 says:

    I dont have “Widget logic” on my widjets.
    The issue is that I can only select pages where to display it, only on one language
    So if have navigation menu En and its translated then only En alone will be displaeed for me. When I select English page from that menu Then only on the english page the widject will be displayed.
    http://gyazo.com/b090cc8ce4853a7d9db9316342847fa3

    So I have no tools (in case to Display widject on specific page) to set widjet on translated pages (menu items).

  3. vladimirK-3 says:

    add widget logic plugin. does not help with the string ICL_LANGUAGE_CODE == ‘sv’
    (sveden)
    only can assign widget for one language menu item

  4. vladimirK-3 says:

    figured out. But its trisky. you should open page on desired language and then add widget and start specifing menu item and it will be displayed on the same language that page is opened now.

    • Amir says:

      I’m not sure that I completely understand your question. This blog post is pretty old and you can do better things today. WPML lets you control on which languages text widgets will appear. Besides this, any other widget will be translated anyway.

  5. nicod-4 says:

    Hi,

    I’ve just released a new plugin that allows you to select the language you want to show the widget on. This is done by a dropdown within every widget.

    My reason to create this plugin is because I cannot justify the risks with Widget Logic.

    I just wanted to share this with you; the plugin is called WPML Widgets and can be downloaded for free on WordPress.org: http://wordpress.org/plugins/wpml-widgets/

Leave a Reply

Please leave here comments about this page only.
For technical support and feature suggestions, head to our forum. We are waiting there!

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


queries in 0.573 seconds.