这是我的第一个问题.
我需要在wordpress cms的帖子中禁用我的图像上的超链接.我在添加图片时知道"无"按钮2帖子但我需要某种过滤器因为我无法重新发布所有199298931092帖子再次进行更改.
我试着在我的主题的functions.php中为the_contetn过滤器添加一些代码但是我不是那么熟练的php-er所以它不起作用.任何建议或帮助.Plz最好的问候 http://www.rofltime.com/
如果您想要内容中的所有图像:
function k99_attachment_image_link_void( $content ) {
$content =
preg_replace(array('{<a[^>]*><img}','{/></a>}'), array('<img','/>'), $content);
return $content;
}
add_filter( 'the_content', 'k99_attachment_image_link_void' );
Run Code Online (Sandbox Code Playgroud)
如果你只想要内容中的附件:
function k99_image_link_void( $content ) {
$content =
preg_replace(
array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}'),
array('<img','" />'),
$content
);
return $content;
}
add_filter( 'the_content', 'k99_image_link_void' );
Run Code Online (Sandbox Code Playgroud)