X

Link keywords or replace text in all blog posts

Managed WordPress hosting

Adding this to the functions.php of your wordpress theme will let you replace text within your blog post. This is a great option for linking multiple pages in your blog with keywords. Don't forget to change the "TEXT_TO_REPLACE" and the "TEXT_YOU_WANT_TO_REPLACE_WITH" lines in the above code add new lines for more items.

Note: Extensive use of this method may cause performance issues, use sparingly.


function replace_text_wps($text) {
	$text = str_replace('TEXT_TO_REPLACE', 'TEXT_YOU_WANT_TO_REPLACE_WITH', $text);
	$text = str_replace('tech support', '<a href="/techsupport">Tech support</a>', $text);
	$text = str_replace('computers', '<a href="/computers">Computers</a>', $text);
	return $text;
}

add_filter('the_content', 'replace_text_wps');

Comments  Leave a Reply

  1. Is this likely to impact speed of the website?

    1. This method would likely impact performance if you replaced a lot of items. However if you used a method like this along with wp-cache or super-cache or many other cache plugins. They would cache Worpress pages in a static file for serving future requests directly from the file rather than loading and compiling the whole PHP code so this would help.

      This is just a nice simple method to replace a few items, I will place a note that excessive use of this could cause performance issues.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!