Monday , February 3 2025

Different content for More Lang language versions in a template using a shortcode

I like More Lang plugin because there are no duplicate pages and posts for other language versions in the admin panel. But I had a problem – for the banners on the home page (which are embedded in the theme) there was no way to change the texts dynamically, depending on the selected language.

Data for testing: each language on the site has its own prefix in the URL (RU, RF and default EN – the prefix is ​​disabled, because the site works with the English version by default).

Here is the code that I add to functions.php in the current theme and the shortcode to use:

function webinp_banner1_shortcode() {
    if(strpos($_SERVER['REQUEST_URI'], 'ru/') !== false){
            return '<div class="alt-font">text for Russian version</div>';
        }
    else if(strpos($_SERVER['REQUEST_URI'], 'fr/') !== false){
            return '<div class="alt-font">text for French version</div>';
        } 
    else return '<div class="alt-font">text for English version</div>';      
}
add_shortcode('banner1shortcode', 'webinp_banner1_shortcode');

Here is the shortcode:

[banner1shortcode]

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

Display the date + a few days from the current one

The task in short: you need to make the delivery date + 5 days from …

Leave a Reply

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