Displaying content conditionally is one of the nicest feature of Oxygen Builder. There are many baked in conditions to play with, however, page language is not among them. With this his code snippet you can display content based on the page language.
Register Condition
Copy this code snippet to your plugin (Code Snippets, Advanced Scripts, WPCodeBox).
//Language
if ( function_exists( 'oxygen_vsb_register_condition' ) ) {
global $oxy_condition_operators;
oxygen_vsb_register_condition(
'Language',
array('options'=>array('hu_HU', 'en_US')),
array('=='),
'thislanguage_callback',
'Other'
);
}
function thislanguage_callback( $value, $operator ) {
$getpagelanguage = get_locale();
global $OxygenConditions;
return $OxygenConditions->eval_string($getpagelanguage, $value, $operator);
}
Condition registering is a feature of Oxygen Builder. In their documentation they explain what the different part of this snippet means. I just would like to highlight a few particles:
- ‘Language’ – Display name of the condition. Your choice.
- array(‘options’=>array(‘hu_HU’, ‘en_US’)) – Replace the language codes in the second array with the language codes of your website.
- ‘thislanguage_callback’ – Name of the callback. Your choice. Don’t forget to replace this name in the second part of the code.
- get_locale() – Built-in WordPress function to retrieve the current locale.
I hope you liked it and had success with the implementation. If you are stuck, contact me to help you.