How to Dynamically Display Different Languages in Visual Composer with Polylang WordPress Plugin
#Customization #DragAndDropPageBuilder #DynamicLanguageDisplay #ElementorAlternative #MultilingualWebsites #MultilingualWordPress #PolylangPlugin #VisualComposerTips #WordPressLanguageSwitcher #WordPressPlugin #WordPressPlugins #WordPressShortcodes #WordPressTranslation #WordPressTutorial
In today's tutorial, I'll walk you through the process of dynamically showing different languages on a WordPress website using the Visual Composer plugin, alongside the Polylang translation plugin. This setup will allow your website to display content in various languages based on user selection. Let’s dive into the details.
Introduction to Visual Composer and Polylang
Visual Composer is a drag-and-drop page builder plugin for WordPress, similar to Elementor, that allows you to create visually appealing pages without writing code. However, if you are using Polylang, a plugin designed to translate your website into multiple languages, it might not directly support dynamic text changes inside Visual Composer. But don’t worry; by using some custom code and shortcodes, you can integrate Polylang to work seamlessly with Visual Composer.
The Problem and the Solution
When I was searching for a solution to dynamically change text inside Visual Composer based on the user's language preference, I realized there wasn't a direct method available from the Polylang plugin. To overcome this limitation, I created a shortcode that responds when a user switches between languages. This shortcode dynamically displays the appropriate text in the selected language on the page. Below is a screenshot from my website, where we have different languages to select from in the header menu.
Step-by-Step Guide
Here’s how you can achieve this functionality:
1. Create a Custom Function
Start by creating a custom function in your functions.php file, which is part of your WordPress theme. This function will allow us to generate dynamic content in multiple languages.
For example, let’s say we want to dynamically display the "About Us" section in different languages. Here’s a sample PHP code that you can copy-paste in your functions.php file:
In this code: ....see further details and codes, videos at 👇
https://www.themeroasters.com/how-to-...
pll_current_language() is a Polylang function that detects the current language.
Based on the current language, it returns the appropriate text (in this case, either English or French).
2. Add a Shortcode
Once you have your custom function, the next step is to register it as a shortcode in WordPress. Shortcodes allow you to insert dynamic content into posts and pages easily.
Now, you can use the shortcode [footeraboutus] anywhere on your website, including Visual Composer elements, and it will display the correct content based on the selected language.
3. Insert Shortcode in Visual Composer
After creating the shortcode, you need to insert it into your Visual Composer page. To do this:
Go to the page you want to edit using Visual Composer.
Click on the element where you want to display the dynamic text.
Paste the shortcode [footeraboutus] inside the element.
Once the page is updated, the content in this section will dynamically change based on the language selected by the user.
Final Steps
After setting up the shortcode and inserting it into the page, all that’s left is to test it. When a user selects a different language (for example, English or French) from the Polylang language switcher, the corresponding content will be displayed automatically.
Like, Follow, Subscribe, Chat with us:
►Subscribe: / @givingbackprosolutions485
► Facebook: / themeroasters
► Twitter: / themeroasters
► Website: https://www.themeroasters.com
About Me:
I am a Web Developer with 9+ years of experience, working with different clients and industries, sectors across the world.
I helped many clients start with their startups, business, hobby projects - my work is related to websites, apps, ecommerce, web-based solutions.
I am not a youtube content creator professionally but by this channel or videos I am sharing my knowledge whatever I can when I get some time so that people get
benefited and making easy for someone who wants to learn or looking for solutions.
What I share:
Experience from Client projects(i keep client's identity and their belongings confidential).
Any solutions that I think are valuable.
My thoughts and problem-solving steps.
Contact for Software-based projects for any stage you are in 1) idea 2) pre-funding 3) scaling 4) established or for a free consultation. Hire me or my team.
Link to professional and beautiful WordPress themes, Ready-made website, or HTML template at https://themeforest.net/user/themeroa...
Смотрите видео How to Dynamically Display Different Languages in Visual Composer with Polylang WordPress Plugin онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pro Solutions 06 Октябрь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1 раз и оно понравилось людям.