If you use a word multiple times on your site and you don’t feel like going through all your posts to replace every instance of it, you can use jQuery to search your page and do the replacing for you. I wanted to replace a word throughout an entire site with a link and all it took was a small piece of code.
If you don’t already have jQuery loaded into your page, include this before your closing <head>
.
That will load up jQuery from Google.
Now you just need to include this in your site’s footer, before the closing <body>
. (Why in the footer? Because including your JavaScript after all of your code is the efficient way to do it.)
Since jQuery doesn’t have a core function for replacing text, we will use the JavaScript replace()
function. The i
after the slash makes the search and replace case-insensitive, and the g
makes it global.
I have the script working on this page to replace every instance of the word jQuery with a link to the jQuery Web site.