Home>Support>“nodeValue.replace” and WordPress Page Builder contents

“nodeValue.replace” and WordPress Page Builder contents

By Dana, 8 years ago. Last reply by Dana, 8 years ago.
Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

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!

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 8 years, 4 months ago Alex S
    Hi, I Work Here

    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.

  2. 8 years, 4 months ago Dana

    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

  3. 8 years, 4 months ago 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/

  4. 8 years, 4 months ago Alex S
    Hi, I Work Here

    Hi Dana,

    Try replacing your code with:

    jQuery(function($){
    	$.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");
    });
    
  5. 8 years, 4 months ago Dana

    That worked!! Thank you so much, I was going crazy :)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More