How can I replace a word only in a <p>
-Tag, and not in a <h3>
or <p class="no-change">
-Tag in the content?
I want to change this:
<p>My Text and an Old Word and more </p>
in
<p>My Text and an New Word and more </p>
I tried this:
function changer($content){
$word = str_replace('Old Word', 'New Word', $content);
$content = preg_replace('/<h3>(.*?)<\/h3>/im', $word, $content);
return $content;
}
add_filter('the_content','changer');
But I get a double result...
Old Word and more
´ – Tada Jun 02 '16 at 17:42