Ronny K
Ronny K

Reputation: 3731

How do I find and replace words in wordpress

I am developing a plugin that is used to find and replace words. So far I have this code and it does not seem to work.

function replace_content($content){

   $wp_post = get_the_content();

   $content = str_replace('lorem',' ronny',$wp_post);

   return $content;

}
add_filter('the_content','replace_content');

Any help will highly be appreciated.

Upvotes: 1

Views: 886

Answers (1)

Ronny K
Ronny K

Reputation: 3731

Found the solution. The content was in capital letters, so i used the str_ireplace() instead of str_replace() function so as to ignore case.

Upvotes: 2

Related Questions