This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

“nodeValue.replace” and WordPress Page Builder contents

8 years ago · Last reply by Dana 8 years ago

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.

Need fast email support? Get SiteOrigin Premium

Replies

5
  1. Alex S Staff 8 years, 11 months ago

    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. Dana 8 years, 11 months ago

    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. Dana 8 years, 11 months ago

    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. Alex S Staff 8 years, 11 months ago

    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. Dana 8 years, 11 months ago

    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.

Have a different question or issue?

Start New Thread