function add_referrer_policy_to_images($content) {
// 正则匹配图片标签,排除特定域名的图片
$pattern = '/<img(.*?)src=["\'](http[s]?:\/\/(?!www\.laomoss\.com|laomoss\.com)[^\s]*)["\'](.*?)>/i';
$replacement = '<img$1src="$2"$3 referrerpolicy="no-referrer">';
// 替换内容
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'add_referrer_policy_to_images');
add_filter('widget_text', 'add_referrer_policy_to_images');
add_filter('widget_text_content', 'add_referrer_policy_to_images');
作者:老默,转载请注明出处:https://www.laomoss.com/4414.html
评论列表(1条)
还以为不更新了