Monday, April 26, 2021
The Great Tit
Updated: 24. 2. 2022, Added: 26. 4. 2021

Show Oxygen Element by current language with WPML

When you use WPML with Oxygen Builder and use 1 template for all languages, then you propably want to display/hide elements conditionally. And of course you can. Use the WPML's filter wpml_current_language to get current language code. Then use the if function to return value you want.

I am returning the language code and then using it in Oxygen builder.

function toolwiki_get_lang() {
$current_language_code = apply_filters( 'wpml_current_language', NULL );
if ($current_language_code == 'cs') {
	return 'cs';
} elseif ($current_language_code == 'en') {
	return 'en';
} elseif ($current_language_code == 'de') {
	return 'de';
} 
}
Conditionally displayed counters
PHP function return value options in Oxygen
WPML current language conditional function in Oxygen

You can also use this function inside code block, for example to display custom fluent form based on current language:

function hrr_get_lang() {
$current_language_code = apply_filters( 'wpml_current_language', NULL );
if ($current_language_code == 'cs') { 
	echo do_shortcode('[fluentform id="5"]');
} 
if ($current_language_code == 'en') {
	echo do_shortcode('[fluentform id="9"]');
} 
if ($current_language_code == 'de') {
	echo do_shortcode('[fluentform id="10"]');
} 
}
echo hrr_get_lang(); ?>
Did I help you? Support me on Patreon!
Beep this article to your friends!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram