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)
- Install WPCode Plugin
- Go to Plugins → Add New
- Search for “WPCode”
- Install and activate the plugin
- Add the Snippet
- Navigate to Code Snippets → Add Snippet
- Choose “Add Your Custom Code (New Snippet)”
- Select “JavaScript Snippet”
- 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
- 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() {
?>
}
add_action('wp_footer', 'add_notranslate_script');
?>
How to Use the No-Translate Protection
In Gutenberg (Block Editor)
- For Entire Blocks:
- Select any block (heading, paragraph, etc.)
- Go to Block Settings → Advanced
- In “Additional CSS Class” field, enter:
notranslate
- For Text Portions:
- Switch to “Code Editor” mode
- Wrap specific text:
<span class="notranslate">Brand Name</span>
In Elementor
- Select any widget (heading, text, button, etc.)
- Go to Advanced tab → CSS Classes
- Enter:
notranslate
In Classic Editor
Switch to “Text” mode and use HTML:
Welcome to TechCorp Solutions
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 Code: SKU-2024-TECH-001
YourBrand Store
$299.99
Business Websites
ABC Solutions Ltd.
Email: info@company.com
123 Business Street
New York, NY 10001
Technical Documentation
function myCustomFunction() {}
Configure your API endpoint settings
Version v2.1.4 includes new features
Testing Your Implementation
- Install Google Translate Extension in your browser
- Visit your site and activate translation
- Verify that elements with notranslate class remain in original language
- Check browser console for confirmation messages (if debug enabled)
Advanced Tips and Tricks
Exclude Entire Sections
Company Information
TechCorp Solutions - Established 2020
Registration: TC-2020-001
Mixed Content Protection
Our company InnovaTech serves clients worldwide with our ProSuite platform.
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!





