Prevent Translating Text with Google Translate Widget

I have the Google Translate widget on a client website and was looking for a way to prevent the translation from working on certain text on a page. In order to do this, I simply had to add the notranslate class to any element on the page that I don’t want to be translated by Google Translate widget.

For example, let’s say that I have an h2 tag called WPLauncher Amazing WordPress Hosting.

<h2>WPLauncher Amazing WordPress Hosting</h2>

Since I would like to prevent translation of this element, I need to add the notranslate class to it, and it will look like the following:

<h2 class="notranslate">WPLauncher Amazing WordPress Hosting</h2>

If I only wanted to block translation of one word in that h2 element, I could do that by adding a span with a notranslate class. For example, I only want to disable translation on my brand name, i.e. WPLauncher, and allow translation on the rest of the text. In this case, the element would look like this:

<h2><span class="notranslate">WPLauncher</span> Amazing WordPress Hosting</h2>

That’s all she wrote! The Google Translate widget should now be blocked for any element that has the notranslate class.

Leave a Reply

Your email address will not be published. Required fields are marked *