Replace content in WordPress on the fly

Replace content in WordPress on the fly:

function replace_content_on_the_fly($text){
	$replace = array(
		// 'words to find' => 'replace with this'
		'wordpress' => '<a href="http://www.wordpress.org/">wordpress</a>',
		'google' => '<a href="http://www.google.com/">excerpt</a>',
		'function' => '<a href="#">function</a>'
	);
	$text = str_replace(array_keys($replace), $replace, $text);
	return $text;
}
add_filter('the_content', 'replace_content_on_the_fly');
add_filter('the_excerpt', 'replace_content_on_the_fly');

4 comments on “Replace content in WordPress on the fly

  1. If you update on the fly - you don't need to click on the update button. There is nothing going out ping wise. It also wont update when the page was last updated anywhere.

    Will Google know the content has been updated?

  2. Excellent and so very useful indeed. It certainly came in useful to recode some embed codes on a site without needing to wade through the entire site.
    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *