威尼斯wnsr888_新葡亰8883ent_威尼斯wns8885556

当前位置: 正汯解答网» 编程语言» 如何让WordPress文章内容里的带链接图片在新窗口打开

如何让WordPress文章内容里的带链接图片在新窗口打开

2023年2月15日 09:03:30 编程语言 0 次浏览

1、打开当前主题模版文件夹下的functions.php文件

2、在其间添加以下代码:

// 文章内容中出现链接在新窗口打开
add_filter( 'the_content','a_blank');
function a_blank($c) {
global $post;
$s = array('/href="(.+?.(jpg|bmp|png|jepg|gif))"/i'=>'href="$1" target="_blank"');
foreach($s as$p => $r){
$c = preg_replace($p,$r,$c);
}
return$c;
}

标签:
Baidu
sogou