0

I must've tried half a dozen scripts (most found here, e.g. at jQuery find and replace string) to replace text on my Wordpress-built site (http://www.sehkelly.com/).

None work. I'm not clever enough to diagnose why (but not stupid enough not to know how to run a script). Into header.php the script goes, in the usual way, and no result.

For instance, all instance of "Shop" on my homepage (in the menu, the h2 elements, in the Wordpress content) remain as such, despite this script ...

$("span, p, div").each(function() {
    var text = $(this).text();
    text = text.replace("Shop", "Sale");
    $(this).text(text);
});

Any ideas?

I have disabled caching plugins to no avail.

Thanks in advance.

UPDATE

In full I have ...

<script type="text/javascript">
    $(document).ready(function(){
        $("span, p, div").each(function() {
        var text = $(this).text();
        text = text.replace("type", "typo");
        $(this).text(text);
    });
</script>

Still no joy.

Community
  • 1
  • 1
Paul Vincent
  • 43
  • 1
  • 9

3 Answers3

1

If you execute such code on your website it will create a mess in your html...Don't do that :)

Do this instead:

$("span, p, div").each(function() {
    var text = $(this).html();
    text = text.replace("Shop", "Sale");
    $(this).html(text);
});
GoR
  • 121
  • 2
  • 10
1

You need to call this in document ready and use regex to replace all instances:

$(function(){
    $("span, p, div").each(function() {
        var text = $(this).text();
        text = text.replace(/Shop/g, "Sale"); // regex instead of string
        $(this).text(text);
    });
});
jcubic
  • 61,973
  • 54
  • 229
  • 402
0

Use this code and then you will be happy

<script type="text/javascript">
    $(document).ready(function(){
    var replaced = $("body").html().replace('Shop','Sale');
    $("body").html(replaced);
    });
</script>
Piyush Dhanotiya
  • 559
  • 4
  • 18