Version: 1.2.0
Author: Riccardo De Martis
LinkedIn URI: https://www.linkedin.com/in/rdemartis
Plugin URI: https://github.com/demartis/conditional-polylang
License: LGPL
Use the [if_lang]
shortcode on its own. This will immediately output its content if the current Polylang language matches the provided code
attribute:
[if_lang code="en"]This content is displayed only when the current language is English.[/if_lang]
Wrap multiple [if_lang]
conditions and an [otherwise]
fallback inside a [conditional_language]
container. The container will output the first matching [if_lang]
content; if none match, the [otherwise]
content will be displayed:
[conditional_language]
[if_lang code="gb"]This is the content for GB.[/if_lang]
[if_lang code="au"]This is the content for Australia.[/if_lang]
[otherwise]This is the content for other languages.[/otherwise]
[/conditional_language]
You can define several conditions within a container for multiple languages, with a fallback if none match:
[conditional_language]
[if_lang code="en"]Content for English users.[/if_lang]
[if_lang code="es"]Contenido para usuarios en español.[/if_lang]
[if_lang code="fr"]Contenu pour les utilisateurs français.[/if_lang]
[otherwise]Default content for users of other languages.[/otherwise]
[/conditional_language]
-
Language Check Function:
Easily check if the current Polylang language matches a specified language code. -
Shortcode Support:
Two types of shortcode usage:- Standalone
[if_lang]
– outputs content immediately if the condition is met. - Container-based
[conditional_language]
– allows grouping multiple[if_lang]
conditions along with an[otherwise]
fallback.
- Standalone
-
Internationalization Ready:
Fully prepared for translation.
- WordPress 4.7 or higher.
- Polylang plugin must be installed and activated.
-
Download the Plugin:
Download the latest release from the Releases page. -
Extract the Archive:
Unzip the downloaded archive to extract the plugin folder. -
Upload the Plugin:
Upload theconditional-polylang
folder to your/wp-content/plugins/
directory. -
Activate the Plugin:
Go to the Plugins menu in your WordPress admin area and activate Conditional Polylang.
This shortcode works outside the container. It immediately outputs its content if the current language matches the specified language code.
Example:
[if_lang code="en"]This content is displayed only when the current language is English.[/if_lang]
Wrap your language-specific content within the [conditional_language]
container to provide multiple conditions along with a fallback.
Example:
[conditional_language]
[if_lang code="gb"]This is the content for GB.[/if_lang]
[if_lang code="au"]This is the content for Australia.[/if_lang]
[otherwise]This is the content for other languages.[/otherwise]
[/conditional_language]
You can also create multiple conditions in one container:
[conditional_language]
[if_lang code="en"]Content for English users.[/if_lang]
[if_lang code="es"]Contenido para usuarios en español.[/if_lang]
[if_lang code="de"]Inhalt für deutsche Benutzer.[/if_lang]
[otherwise]Fallback: Content for users of other languages.[/otherwise]
[/conditional_language]
The plugin provides a helper function conditional_polylang_is_language( $language )
that returns true
if the current Polylang language matches the specified language code. For example:
if ( conditional_polylang_is_language( 'en' ) ) {
// Execute code for English language.
}
- Updated shortcode syntax:
[if_lang]
now expects acode
attribute instead oflang
.[otherwise]
is used as the fallback shortcode instead of[else_lang]
.
- Improved support for standalone
[if_lang]
usage outside of the container. - Updated documentation with multiple usage examples.
- Added new shortcode syntax:
[conditional_language]
,[if_lang]
, and[else_lang]
. - Improved support for standalone
[if_lang]
usage outside of the container. - Updated documentation with multiple usage examples.
- Initial release of Conditional Polylang by Riccardo De Martis.
This plugin is licensed under the LGPL license.
For support, updates, or further requests, please use the GitHub Issues page.