I am using ipinfo.io to change the spelling of certain words on my WordPress site. In this case, changing the “colour/color” spellings based on US/CA ip info.
This script below is working on standard WordPress post pages, however I need it to work on my home page, which uses the Page Builder plugin to create the content. None of the words are being replaced even though the source view displays the content as html.
<script> $.get("http://ipinfo.io", function(response) { if(response.country == "US") { $('body :not(script)').contents().filter(function() { return this.nodeType === 3; }).replaceWith(function() { return this.nodeValue.replace(/Watercolour/g,'Watercolor').replace(/colour/g,'color'); }); } }, "jsonp"); </script>
Does this have to do with the nodeType or is it something else? I can’t sort out how to get this to work properly on the home page with the Page Builder text content. My code is placed in the footer.php theme file.
TIA!
Hi Dana,
Do you have a public URL where we can take at the script working? To be honest, I’m not too sure why it might not be working.
Hi Alex,
Yes, check http://watercolour-workshop.com. The script is at the bottom of the source code. It’s set up right now to only change the wording for US based people.
Thanks,
Dana
Sorry, I posted a link to the home page which is where it is NOT working. This blog post on the other hand (without the page builder) is working: http://watercolour-workshop.com/the-benefits-of-painting-on-mental-health/
Hi Dana,
Try replacing your code with:
That worked!! Thank you so much, I was going crazy :)