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:
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.
Add language conditions per widgets
Click to edit each of these widgets and add the language conditions to the Widget Logic field.
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|