我有一个这样的 anchor 元素:
<a href="/link-to-image/" rel="attachment wp-att-7076"><img src="/uploads/img.jpg" alt="" title="" width="1268" height="377" class="alignnone size-full wp-image-7076" /></a>
(这是 Wordpress 在帖子中嵌入上传图片的标准方式。)
我想移除图像元素周围的 anchor ,但保留图像。我只是想让图像显示而无需点击。
这可以通过对 Wordpress 中的帖子内容进行过滤器或在使用 javascript 加载页面之后来完成。在 Wordpress 中过滤将是首选。我不知道如何执行这两个选项中的任何一个。
最佳答案
查找有用的代码 here :
已尝试,但导致无效代码。
../your_theme/functions.php 中的代码如下所示:
function remove_anchor($content) {
// the code for removing the anchor here
$content =
preg_replace(
array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}', '{</a>}'),
array('<img',''),
$content
);
return $content;
}
// then use WP's filter/hook system like this:
add_filter('the_content', 'remove_anchor');
关于php - 使用过滤器(或 jquery)删除 Wordpress 图像周围的 anchor 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3829786/