reg*_*gie 5 php wordpress filter
我有一个像这样的锚元素:
<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>
Run Code Online (Sandbox Code Playgroud)
(这是Wordpress在帖子中嵌入上传图片的标准方式.)
我想删除图像元素周围的锚点,但保留图像.我只是希望图像显示而不是可点击的.
这可以通过过滤Wordpress中帖子的内容或在页面加载javascript后完成.在Wordpress中过滤将是首选.我不知道如何做这两个选项中的任何一个.
进入 WP 主题文件夹,编辑“functions.php”。添加这样的代码:
function remove_anchor($data)
{
// the code for removing the anchor here
// (not sure if you need help there, too).
// you will work on the $data string using DOM or regex
// and then return it at the end
return $data;
}
// then use WP's filter/hook system like this:
add_filter('the_content', 'remove_anchor');
Run Code Online (Sandbox Code Playgroud)
这add_filter
意味着每次显示帖子时,remove_anchor
都会调用该函数。
jQuery 可能更容易,你只需要识别图像而不是让它们可点击(这是未经测试的)
$(document).ready(function()
{
$('#post a.some-class-name').click(function()
{
return false;
}
});
Run Code Online (Sandbox Code Playgroud)