Replace Text That Loco Translate Can’t Reach

Recommendation

Learn why I switched to WPCodeBox for managing code snippets for myself and for my clients.

Instructions

Snippet Type: JavaScript

  1. Copy the snippet.
  2. Add the snippet using WPCodeBox.
  3. Follow any customization notes provided.
  4. Save the snippet.
  5. Enable the snippet.
  6. Test.

Snippet

There are external elements like Mapbox, Google Maps, etc. that plugins like Loco Translate cannot reach and in those instances, this snippet can be used.

				
					// REPLACE TEXT THAT LOCO TRANSLATE CAN'T REACH
jQuery(document).ready(function ($) {
  $(".item-property").each(function () {
    var text = $(this).text();
    $(this).text(
      text.replace("enter-the-original-text", "enter-your-new-text")
    );
  });
});