I was trying to replace keywords in post content to links, however, I realise the keywords in alt attribute of img tag was also affected.
Is there solution for that? BTW, the code I was using in functions.php:
function replace_text_wp($text){
$replace = array(
'keyword1' => '<a href="http://demo.com/" rel="bookmark" title="keyword1">keyword1</a>',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter(‘the_content’, ‘replace_text_wp’);
I had to do something similar not too long ago, try this as your function – it might well need some fiddling and tweaking as I am adapting it to your example without testing