How to Display Different Widgets Per Language via WPML
Widgets Per Language – 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. This article will show you how to do this using Widget Logic.
Widgets Per Language
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.
Widgets Per Language – Before we begin, download and activate Widget Logic: https://wordpress.org/extend/plugins/widget-logic/
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.
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.
You should expect to see the different widgets per language now.