首页 > 作文

wordpress网站文章添加超链接如何避免权重流失?

更新时间:2023-04-08 23:35:26 阅读: 评论:0

将以下代码添加到当前使用主题的functions.php文件中即可。

代码预览

// 文章页面外链自动添加nofollow属性和新窗口打开add_filter( 'the_content', 'cn_nf_url_par');function cn_nf_url_par( $content ) {$regexp = "<a\s[^>v是什么元素]*href=(\"??)([^\" >]*?)\[^>]*>";if(preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {if( !empty($matches) ) {$srcUrl = get_option('siteurl');for ($i=0; $i < count($matches); $i++){$tag = $matches[$i][0];$tag2 = $matches[$i][0];$url = $matches[$i][0桂林山水风景图片];$noFollow = '';$pattern = '/target\s*=\s*"\s*_blank\s*"/';preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);if( count($match) < 1 )$noFollow .= ' target="_blank" ';$pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);if( count($match) < 1 )$noFollow .= ' rel="nofollow" ';$pos = strpos($url,$srcUrl);if学法心得 ($pos === fal) {$tag = rtrim ($tag,'>');$tag .= $noFollow.'&g不辍劳作t;';$content = str_replace($tag2,$tag,$content);}}}}$content = str_re黑焰place(']]>', ']]>', $content);return $content;}

以上代码意思是,自动给外链自动添加nofollow属性(rel=”nofollow”)和新窗口打开属性(target=”_blank”),如果手动添加了这两个属性则不自动添加。

如果不给这些外链添加nofollow标签,可能会造成我们自己站点的权重流失。如果这些外链不是通过_blank方式打开,可能会给访客造成不好的体验。

本文地址:https://blog.csdn.net/weixin_43837883/article/details/109564679

本文发布于:2023-04-08 23:35:24,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/3f1b0985a89329303e03d44786b1ceb2.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:wordpress网站文章添加超链接如何避免权重流失?.doc

本文 PDF 下载地址:wordpress网站文章添加超链接如何避免权重流失?.pdf

下一篇:返回列表
标签:属性   代码   新窗口   可能会
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图