Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 仅当链接指向Wordpress站点的图像时,才禁用图像链接_Php_Regex_Wordpress_Image_Function - Fatal编程技术网

Php 仅当链接指向Wordpress站点的图像时,才禁用图像链接

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

我正在寻找一个代码来放入我的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 ) {
    $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和文档

你们谁能帮忙

非常感谢。

请阅读和,请阅读和