从博客中的每个WordPress博客帖子中删除rel =“ noopener noreferrer”

时间:2019-05-25 16:12:26

标签: html wordpress

我有一个博客,其中包含50多个博客帖子,但我意识到这些帖子中的所有内部链接都包含rel="noopener noreferrer"。反正有将它们全部删除在WordPress中吗?也许是Functions.php的插件或脚本?

我进行了研究,找不到任何有用的内容。

1 个答案:

答案 0 :(得分:0)

您可以使用preg_replace来更改WordPress中内容的代码。

add_filter('the_content', 'remove_link_rel');
function remove_link_rel($content){
    $content = preg_replace('~<a(.*?)rel="noopener noreferrer"(.*?)>~i', '<a$1$2>', $content);
    return $content;
}

以上代码检查包含rel="noopener noreferrer"属性的链接,然后将其删除。将此代码添加到主题的functions.php文件中。

https://www.phpliveregex.com/p/sey#tab-preg-replace

相关问题