Using the_content to replace text
-
I am interested in creating a very simple text replace plugin. I am aware of several plugins that already do text replace per post, but it seems that all of them do so on the fly or dynamically. What I am interested in is doing it once, and hard coding it into the DB. For example, everytime the word ‘beer’ shows up in a post it is replaced with
beer
. Below is pasted from the codex, how would I do somthing similar except permanently modify the post.the_content
passed the content as a string. The following plugin snippet would replace all instances of the word foo with bar, wihtout modifying the contents of the post as stored in the database:
add_filter('the_content', 'foo_bar');function foo_bar ($content = '') {
return preg_replace("/foo/", "bar", $content);
}Or is there a better way to do this in geneneral, perhaps using a different hook?
Thanks for anyhelp!
- The topic ‘Using the_content to replace text’ is closed to new replies.