Automatically replace words in your posts

Automatically replace words in your posts

Imagine this: your blog was named “myblog” and for some reason you renamed it “mysuperblog”. Don’t edit your XXX posts to replace every single occurence! Instead, paste this useful hook into your functions.php file and let it do the work for you.

function replace_text_wps($text){

$replace = array(

// ‘WORD TO REPLACE’ => ‘REPLACE WORD WITH THIS’

‘wordpress’ => ‘wordpress‘,

‘excerpt’ => ‘excerpt‘,

‘function’ => ‘function

);

$text = str_replace(array_keys($replace), $replace, $text);

return $text;

}

add_filter(‘the_content’, ‘replace_text_wps’);

add_filter(‘the_excerpt’, ‘replace_text_wps’);