Php 仅当链接指向Wordpress站点的图像时,才禁用图像链接
我正在寻找一个代码来放入我的custom-functions.php,它只会禁用链接到图像的图像链接(jpg、jpeg、png、gif等) 我使用了本页提供的代码: 这是我在custom-functions.php中插入的代码Php 仅当链接指向Wordpress站点的图像时,才禁用图像链接,php,regex,wordpress,image,function,Php,Regex,Wordpress,Image,Function,我正在寻找一个代码来放入我的custom-functions.php,它只会禁用链接到图像的图像链接(jpg、jpeg、png、gif等) 我使用了本页提供的代码: 这是我在custom-functions.php中插入的代码 add_filter( 'the_content', 'attachment_image_link_remove_filter' ); function attachment_image_link_remove_filter( $content ) { $con
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;
}
add_filter('the_content'、'attachment_image_link_remove_filter');
函数附件\图像\链接\删除\过滤器($content){
$content=
预更换(
数组(“{]*>”),
$content
);
返回$content;
}
但它太强大了,并且禁用了围绕图像的每个链接。我仍然希望链接指向页面、帖子、PDF和文档
你们谁能帮忙
非常感谢。请阅读和,请阅读和