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="">wordpress</a>',
		'google' => '<a href="">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 thoughts on “Replace content in WordPress on the fly

  1. Dave

    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. Martin Koss

    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 *