I'm trying to filter my content and on matches on flow I would like to change my html structure, but my rule doesn't really apply. I have the following filter which searches the first image of posts and on rule match attaching a css container. The preg_match_all
is working but the str_replace
doesn't
function imageFooter($content){
global $post, $posts;
preg_match_all('/<a.href="(.*?)"><img.*?src="(.*?)".*?><\/a>/', $post->post_content, $matches);
$to_search = $matches[0][0];
$replacement = '<div class="image_footer">'.$matches[0][0].'<span class="logo"></span></div>';
str_replace($to_search , $replacement, $post->post_content);
return $content;
}
add_filter('the_content', 'imageFooter');