Wordpress Technology

Wordpress Tips, Tutorials, Hacks

Replace Content in All Posts

Let’s imagine we have to replace in all posts of wordpress the chunk of text at once, or highlite the word, or put the link, etc.

To edit every post might take a long time.

There is an elegant and simple solution to achieve the task.

function replace_text($text) {
	$text = str_replace('WordPress', '<strong>WordPress</strong>', $text);
	$text = str_replace('WordPress hacks', '<a href="#">WordPress hacks</a>', $text);
	return $text;
}

add_filter('the_content', 'replace_text');

The code must be inserted into functions.php file of current theme.


Both comments and pings are currently closed.

© 2009 | Made by Vancouver Web Design | Internet Marketing