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.
- Go to WPML → Settings → Post Types.
- 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.
- Translatable – only show translated items
- Translate only the parts of the code that need localization.
- 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:
- Create a new Options Page with ACF.
- Add a Textarea field for inserting your custom code.
- Create a PHP function to output the code (e.g., in
header.phporfooter.php). - 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:
- Create a Custom HTML tag with your code.
- Set a Page View trigger (or other trigger type).
- Use the built-in variable Page Path.
- 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.