Stop Google Translate and Other Auto-Translation Services from Translating Your Brand Names, Codes, and Specific Content
Elementor, Tools, Websites, WordPress customization

How to Prevent Auto-Translation of Specific Text in WordPress

Stop Google Translate and Other Auto-Translation Services from Translating Your Brand Names, Codes, and Specific Content
Stop Google Translate

The Problem Every WordPress Site Owner Faces

Have you ever noticed that automatic translation services like Google Translate, Bing Translator, or browser-based translation tools sometimes translate content that shouldn’t be translated? Brand names become unrecognizable, product codes get mangled, and technical terms lose their meaning.

Imagine your brand “TechCorp” being translated to “Società Tecnologica” in Italian, or your product code “PRO-2024-001” becoming “PROFESSIONALE-2024-001”. Not exactly the professional look you’re going for, right?

The Solution: Smart CSS Class Implementation

The standard approach is to use the notranslate CSS class, but here’s the catch: while Google Translate recognizes this class, other translation services and browsers might ignore it. That’s where our comprehensive solution comes in.

Our JavaScript snippet doesn’t just add the notranslate class – it implements multiple protection layers that work with all major translation services, including:

  • Google Translate
  • Bing Translator
  • Browser built-in translation
  • Third-party translation plugins
  • Mobile browser translation

What Makes This Solution Special?

Universal Compatibility: Works with any WordPress setup – Gutenberg, Elementor, Divi, classic editor, custom themes, and even dynamically loaded content.

Performance Optimized: Uses efficient DOM observers that only activate when needed, preventing any slowdown on your site.

Future-Proof: Automatically handles new content added via AJAX, page builders, or any dynamic loading system.

Easy Implementation: Just add one snippet to your site, then use a simple CSS class anywhere you need protection.

Step-by-Step Installation Guide

Method 1: Using WPCode Plugin (Recommended)

  1. Install WPCode Plugin
    • Go to Plugins → Add New
    • Search for “WPCode”
    • Install and activate the plugin
  2. Add the Snippet
    • Navigate to Code Snippets → Add Snippet
    • Choose “Add Your Custom Code (New Snippet)”
    • Select “JavaScript Snippet”
  3. Configure the Snippet
    • Paste the code below in the code area
    • Set Title: “No-Translate Protection”
    • Location: “Site Wide Header” or “Everywhere”
    • Device: “Any Device”
    • Set to Active
  4. Save and Test
    • Click “Save Snippet”
    • Your protection is now active site-wide!
				
					// No-Translate Protection for WordPress
// Prevents auto-translation of elements with 'notranslate' class
// Compatible with all translation services and page builders

(function() {
    'use strict';
    
    // Function to apply translation protection
    function applyNoTranslate() {
        // Select all elements with 'notranslate' class
        const noTranslateElements = document.querySelectorAll('.notranslate');
        
        noTranslateElements.forEach(function(element) {
            // Add multiple protection attributes for maximum compatibility
            element.setAttribute('translate', 'no');           // HTML5 standard
            element.setAttribute('lang', 'x-no-translate');    // Language override
            element.setAttribute('data-no-translate', 'true'); // Custom attribute
            element.classList.add('notranslate');             // Google Translate class
            
            // Additional protection for specific translation services
            element.setAttribute('data-translate', 'no');
            element.setAttribute('data-gtranslate', 'no');
        });
        
        // Debug info (remove in production if needed)
        if (noTranslateElements.length > 0) {
            console.log('✅ No-translate protection applied to ' + noTranslateElements.length + ' elements');
        }
    }
    
    // Apply protection when DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', applyNoTranslate);
    } else {
        applyNoTranslate(); // DOM already loaded
    }
    
    // Watch for dynamically added content (AJAX, page builders, etc.)
    const observer = new MutationObserver(function(mutations) {
        let shouldReapply = false;
        
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                mutation.addedNodes.forEach(function(node) {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        // Check if new node or its children have notranslate class
                        if ((node.classList && node.classList.contains('notranslate')) || 
                            (node.querySelector && node.querySelector('.notranslate'))) {
                            shouldReapply = true;
                        }
                    }
                });
            }
        });
        
        if (shouldReapply) {
            // Small delay to let DOM stabilize
            setTimeout(applyNoTranslate, 100);
        }
    });
    
    // Start observing the entire document
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
    
    // Additional triggers for better compatibility
    window.addEventListener('load', applyNoTranslate);
    
    // Elementor compatibility
    if (typeof elementorFrontend !== 'undefined') {
        elementorFrontend.hooks.addAction('frontend/element_ready/global', applyNoTranslate);
    }
    
    // Divi compatibility  
    if (typeof ET_Builder !== 'undefined') {
        document.addEventListener('et_pb_after_init_modules', applyNoTranslate);
    }
    
})();
				
			

Method 2: Theme Functions.php (Alternative)

If you prefer not to use a plugin, add this to your theme’s functions.php:

				
					// Add no-translate JavaScript to site
function add_notranslate_script() {
    ?>
    <script>
    (function() {
        'use strict';
        
        function applyNoTranslate() {
            const noTranslateElements = document.querySelectorAll('.notranslate');
            
            noTranslateElements.forEach(function(element) {
                element.setAttribute('translate', 'no');
                element.setAttribute('lang', 'x-no-translate');
                element.setAttribute('data-no-translate', 'true');
                element.classList.add('notranslate');
                element.setAttribute('data-translate', 'no');
                element.setAttribute('data-gtranslate', 'no');
            });
            
            if (noTranslateElements.length > 0) {
                console.log('✅ No-translate protection applied to ' + noTranslateElements.length + ' elements');
            }
        }
        
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', applyNoTranslate);
        } else {
            applyNoTranslate();
        }
        
        const observer = new MutationObserver(function(mutations) {
            let shouldReapply = false;
            mutations.forEach(function(mutation) {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    mutation.addedNodes.forEach(function(node) {
                        if (node.nodeType === Node.ELEMENT_NODE) {
                            if ((node.classList && node.classList.contains('notranslate')) || 
                                (node.querySelector && node.querySelector('.notranslate'))) {
                                shouldReapply = true;
                            }
                        }
                    });
                }
            });
            if (shouldReapply) {
                setTimeout(applyNoTranslate, 100);
            }
        });
        
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
        
        window.addEventListener('load', applyNoTranslate);
        
        if (typeof elementorFrontend !== 'undefined') {
            elementorFrontend.hooks.addAction('frontend/element_ready/global', applyNoTranslate);
        }
        
        if (typeof ET_Builder !== 'undefined') {
            document.addEventListener('et_pb_after_init_modules', applyNoTranslate);
        }
    })();
    </script>
}
add_action('wp_footer', 'add_notranslate_script');
?>
				
			

How to Use the No-Translate Protection

In Gutenberg (Block Editor)

  1. For Entire Blocks:
    • Select any block (heading, paragraph, etc.)
    • Go to Block Settings → Advanced
    • In “Additional CSS Class” field, enter: notranslate
  2. For Text Portions:
    • Switch to “Code Editor” mode
    • Wrap specific text: <span class="notranslate">Brand Name</span>

In Elementor

  1. Select any widget (heading, text, button, etc.)
  2. Go to Advanced tab → CSS Classes
  3. Enter: notranslate

In Classic Editor

Switch to “Text” mode and use HTML:

				
					<p>Welcome to <span class="notranslate">TechCorp Solutions</span></p>
				
			

In Other Page Builders (Divi, Beaver Builder, etc.)

Look for “CSS Class” or “Custom CSS” options and add notranslate.

Real-World Examples

E-commerce Sites

				
					<!-- Product codes -->
<p>Product Code: <span class="notranslate">SKU-2024-TECH-001</span></p>

<!-- Brand names -->
<h1 class="notranslate">YourBrand Store</h1>

<!-- Prices with currency -->
<span class="price notranslate">$299.99</span> 
				
			

Business Websites

				
					<!-- Company name -->
<h2 class="notranslate">ABC Solutions Ltd.</h2>

<!-- Contact information -->
<p>Email: <a href="mailto:info@company.com" class="notranslate">info@company.com</a></p>

<!-- Addresses -->
<address class="notranslate">
123 Business Street<br>
New York, NY 10001
</address>
				
			

Technical Documentation

				
					<!-- Code examples -->
<code class="notranslate">function myCustomFunction() {}</code>

<!-- Technical terms -->
<p>Configure your <span class="notranslate">API endpoint</span> settings</p>

<!-- Version numbers -->
<p>Version <span class="notranslate">v2.1.4</span> includes new features</p> 
				
			

Testing Your Implementation

  1. Install Google Translate Extension in your browser
  2. Visit your site and activate translation
  3. Verify that elements with notranslate class remain in original language
  4. Check browser console for confirmation messages (if debug enabled)

Advanced Tips and Tricks

Exclude Entire Sections

				
					<div class="notranslate">
  <h3>Company Information</h3>
  <p>TechCorp Solutions - Established 2020</p>
  <p>Registration: TC-2020-001</p>
</div> 
				
			

Mixed Content Protection

				
					<p>Our company <span class="notranslate">InnovaTech</span> serves clients worldwide with our <span class="notranslate">ProSuite</span> platform.</p> 
				
			

CSS Styling Integration

				
					.notranslate {
    /* Your custom styling */
    font-weight: bold;
    color: #333;
}
				
			

Troubleshooting Common Issues

Problem: “The script doesn’t seem to work”
Solution: Check browser console for errors and ensure WPCode is set to “Everywhere” or “Site Wide Header”

Problem: “Works in Gutenberg but not in my page builder”
Solution: The script includes specific compatibility code for major page builders. Try adding a small delay or contact us for specific builder support.

Problem: “Some elements still get translated”
Solution: Make sure you’re adding the class correctly and that there are no JavaScript errors on your page.

Why This Solution is Superior

Traditional approaches only use the basic notranslate class, which works inconsistently across different translation services.

Our solution implements a comprehensive protection system that:

  • Uses multiple HTML attributes for broader compatibility
  • Automatically handles dynamic content
  • Works with all major page builders
  • Provides debugging information
  • Requires zero maintenance

Browser and Service Compatibility

  • Google Translate (Chrome extension & website widget)
  • Microsoft Translator (Edge browser)
  • Safari Translation (iOS/macOS)
  • Firefox Translation (built-in feature)
  • Third-party translation plugins (GTranslate, WPML, etc.)
  • Mobile browser translation (iOS/Android)

Performance Impact

This solution is designed with performance in mind:

  • Lightweight: ~2KB of JavaScript code
  • Efficient: Only processes elements that need protection
  • Non-blocking: Doesn’t affect page load speed
  • Smart detection: Uses optimized DOM observers

Conclusion

Protecting your brand names, product codes, and specific content from unwanted auto-translation is crucial for maintaining your site’s professional appearance and user experience. This comprehensive solution ensures your content stays exactly as you intended, regardless of which translation service your visitors use.

The best part? It’s a one-time setup that works automatically with any content you add to your site, whether through Gutenberg, Elementor, or any other method.

Ready to protect your content?

Copy the code above and implement it today!

Need help with this solution or looking for custom development?

Visit my Stay In Touch page to connect and discuss your project. Discover a range of web development services and specialized WordPress solutions tailored to your needs. Let's work together to enhance your digital presence.