Insights

How to Add Elementor Custom Code for One Language (or Different Code per Language) with WPML & Polylang

Table of Contents

A step-by-step guide to displaying Elementor Custom Code in just one language or using different code versions across languages with WPML, Polylang, ACF, and Google Tag Manager.

Challenge

When working on multilingual WordPress websites, translating Elementor Custom Code can be tricky — especially if you’re using WPML, Polylang, or other translation solutions. Without the right approach, your scripts may display only in one language or fail to appear where needed.

Solution

By adjusting translation settings or applying targeted workarounds, you can make Elementor Custom Code fully multilingual — without breaking your site layout or duplicating unnecessary scripts.

Translating Custom Code with WPML

WPML allows you to manage Elementor Custom Code translations just like posts, pages, or templates.

  1. Go to WPML → Settings → Post Types.
  2. Enable translations for your Custom Post Type. Choose one of the two options:
    • Translatable – only show translated items
      → The code appears only if a translation exists.
    • Translatable – use translation if available or fallback to default language
      → If no translation exists, the default language version will appear.
  3. Translate only the parts of the code that need localization.
  4. If the code should work only in a specific language, switch the WordPress admin language before creating it.

💡 Tip: Custom Code uses the Classic WordPress Editor for translations.

Translating Custom Code with Polylang

Polylang does not natively support Elementor Custom Code translations — but you can work around it.

Option A: Cookie Category Method

  • Add the custom code to the “Necessary” cookie category in the target language if the cookie plugin supports this solution.

Option B: Language-Specific Hooks in functions.php

add_action('wp_head', function () {
    if ( function_exists( 'pll_current_language' ) && pll_current_language() === 'fr' ) {
        echo "<script>console.log('Bonjour');</script>";
    } else {
        echo "<script>console.log('Hello');</script>";
    }
});

Option C: ACF Options Page (Scalable Solution)

For larger projects where multilingual custom code must be managed centrally:

  1. Create a new Options Page with ACF.
  2. Add a Textarea field for inserting your custom code.
  3. Create a PHP function to output the code (e.g., in header.php or footer.php).
  4. Use AI-assisted coding to build this step-by-step for scalability.

💡 Tip: Use AI tools to help generate these PHP snippets for your specific case.

Google Tag Manager Method (Tracking Scripts)

If Google Tag Manager is active and not blocked by cookies, you can use it to insert language-specific scripts.

Steps:

  1. Create a Custom HTML tag with your code.
  2. Set a Page View trigger (or other trigger type).
  3. Use the built-in variable Page Path.
  4. Set the trigger condition to match a RegEx pattern.

Example for Czech version:

^/cz(?:/.*)?(?:\?.*)?$

Result

By following these methods, you ensure Elementor Custom Code behaves correctly across all languages, providing consistent user experience and optimized performance.

Picture of Roman Vlčák

Roman Vlčák

An incorrigible perfectionist passionate about pixel-perfect work, who constantly strives to deliver the highest possible quality. Outside of Webgate, he is a caring husband and father to his young son. In his free time, he likes traveling with his family and doing puzzles.

Senior WordPress Developer • Co-founder

Share this artcle

Let's work together!

Get a free consultation with our experts

Subscribe to our quarterly newsletter and receive latest insights.

Topics: Improving B2B websites, AI tools in web development, UX/UI, website marketing trends etc.

By submitting this form you agree to the processing of your personal data according to our .

Contact

Let's work together!

Get a free consulting call with our experts

Book a call with
Webgate founders

Thank you for your interest!

We will contact you soon.