wordpress如何在网站中出现外链的时候自动添加”nofollow“标签,下面web建站小编给大家详细介绍一下具体实现代码!
打开主题下functions.php
,新增以下代码:
add_filter('the_content', 'auto_nofollow'); function auto_nofollow($content) { return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content); } function auto_nofollow_callback($matches) { $link = $matches[0]; $site_link = get_bloginfo('url'); if (strpos($link, 'rel') === false) { $link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link); } elseif (preg_match("%href=S(?!$site_link)%i", $link)) { $link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link); } return $link; }
上面是“wordpress如何在网站中出现的外链自动添加"nofollow"标签”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3523.html
workflows工作流
一颗巨型的木星ComfyUI工作流
一个可爱的口袋妖怪ComfyUI工作流
文生图工作流:图片合并comfyui工作流
一张由表情符号组成的照片ComfyUI工作流
在森林中心有一座蛇形的房子ComfyUI工作流
一个外国人在吹奏萨克斯ComfyUI工作流
梦幻中的一只猫咪ComfyUI工作流
大黄蜂空中决战ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!