您尚未设置$content 它只是返回传递给函数的相同内容。阅读文档str_replace. 您应该具备:
$content = str_replace($to_search , $replacement, $post->post_content);
但你为什么要做手术
$post->post_content? 帖子内容将传递到过滤器中。您甚至有一个名为
$content 您没有使用的。你正在做的事可能会引起麻烦。想想这个。
您的站点上有4个筛选器the_content 包括你的。
使用$content使用$content 如过滤器1所修改,因为它们“连锁”使用$content 由前两个过滤器修改您的过滤器使用$post->content 在“链条”之外。您刚刚删除了前面的所有过滤器此外,您没有使用$posts 完全
您的代码应为:
function imageFooter($content){
preg_match_all(\'/<a.href="(.*?)"><img.*?src="(.*?)".*?><\\/a>/\', $content, $matches);
$to_search = $matches[0][0];
$replacement = \'<div class="image_footer">\'.$matches[0][0].\'<span class="logo"></span></div>\';
$content = str_replace($to_search , $replacement, $content);
return $content;
}
add_filter(\'the_content\', \'imageFooter\');
应该提醒您,使用regex解析HTML是非常危险的。很容易出错。