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工作流
坐落在白雪覆盖的广阔平原上2只可爱的雪豹
树上挂着一只表情可爱的香蕉ComfyUI工作流二
一只迷人的黑豹ComfyUI工作流
海中一头鲸鱼ComfyUI工作流
一轮月亮悬挂在树上的天空中ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!