当从编辑器上传图片并发布帖子时,我看到所有图片都有链接。如何删除它
Remove link from post images
3 个回复
最合适的回答,由SO网友:john23klipp 整理而成
这应该可以奏效。过滤器将检查图像并删除a(链接)标记。只需将其添加到主题的功能中即可。php:
add_filter( \'the_content\', \'attachment_image_link_remove_filter\' );
function attachment_image_link_remove_filter( $content ) {
$content =
preg_replace(
array(\'{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}\',
\'{ wp-image-[0-9]*" /></a>}\'),
array(\'<img\',\'" />\'),
$content
);
return $content;
}
SO网友:henZa
我尝试了上述解决方案,但在查看源代码时,我发现了错误的链接关闭标记:</a>
我找到了这个有效的解决方案:
function attachment_image_link_remove_filter($content) {
$content =
preg_replace(
array(\'{<a[^>]*><img}\', \'{/></a>}\'),
array(\'<img\', \'/>\'),
$content
);
return $content;
}
add_filter(\'the_content\', \'attachment_image_link_remove_filter\');
感谢@noman的回答this postSO网友:Nicolai Grossherr
通过»媒体库«模式插入图像时,单击»添加媒体«后,选择»无«作为»链接至«附件显示设置«部分。要删除已链接图像的链接,请单击该图像,然后按»删除链接«按钮。
结束