wordpress各种地方添加nofllow方法集合

文章目录
[隐藏]

nofllow标签能够让搜索引擎自动识别,不对该链接进行爬取,用的好的话能有效防止网站权.重分散,有效提高页面权.重,对于网站的搜索优化很有用。以下我集结了wordpress各种添加nofollow的方法及代码。

为文章标签添加rel=”nofollow”

在 functions.php中添加如下代码即可:

add_filter('the_tags','the_tags_nofollow');
function the_tags_nofollow($tag){
$tag=preg_replace('/<a /','<a rel="nofollow" ',$tag);
return $tag;
}

为标签云添加rel=”nofollow”

同样在 functions.php中添加如下代码即可:

add_filter('wp_tag_cloud
','tag_cloud_nofollow');
function tag_cloud_nofollow($cloud){
$tag=preg_replace('/<a /','<a rel="nofollow" ',$cloud);
return $cloud;
}

为WordPress“继续阅读”添加Nofollow标签

在 functions.php中添加如下代码:

function my_more_link($link){
//禁止more标签自动跳转
$link=preg_replace('/#more-\d+/i','',$link);
//more标签外围加了一层 p
$link=str_replace('<a','<p><a rel="nofollow" title="继续阅读: '.get_the_title($post->post_title).'"',$link);
//闭合新包裹的 p
$link=str_replace('</a>','</a></p>',$link);
return $link;
}
add_filter('the_content_more_link','my_more_link');

或者在functions.php中找到read-more并加入rel=“nofollow”就可以了

记住nofollow书写规范为:<a rel=“nofollow” href=……………..></a>

为文章内容中不是本站链接添加NOFOLLOW

同样在functions.php中添加代码,

add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($content){
preg_match_all('/href="(.*?)" rel="external nofollow" /',$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false ) $content=str_replace("href=\"$val\"", "href=\"$val\" rel=\"external nofollow\" ",$content);
}
}
return $content;
}

为@**评论链接添加nofollow

在functions.php添加代码。

function add_nofollow_to_comments_popup_link(){ return ' rel="nofollow" '; }

add_filter(‘comments_popup_link_attributes’, ‘add_nofollow_to_comments_popup_link’);

为评论作者链接添加external nofollow并在新窗口打开

在functions.php添加代码,

function comment_author_link_window() {
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href=$url rel='external nofollow' target='_blank'>$author</a>";
return $return;
}
add_filter('get_comment_author_link', 'comment_author_link_window');

而external意为“外部”。

友情链接如何添加Nofollow标签

1.找到“/wp-admin/includes/meta-boxes.php”文件;

2.查找“<table cellpadding=”3″ cellspacing=”5″>”;

3.在合适位置插入代码:

<label for=”Nofollow”> <input class=”valinp” type=”checkbox” name=”physical” value=”nofollow” id=”nofollow” <?php xfn_check(‘physical’, ‘nofollow’); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(‘加nofollow’) ?></label>

4.保存并更新文件即可,在后台打开友链添加页面可看到。

不过自wordpress3.5版本以后后台“链接”选项被去掉了,但是之后的版本都有保留这个功能,要想调出来,可在functions.php中添加

/*启用友情链接*/
add_filter( 'pre_option_link_manager_enabled', '__return_true' );

 

最后我要说一下,以上资源部分来自互联网,具体出处不清楚,还有我不敢保证以上代码对于每一种主题都适用,用的时候请确定代码在functions.php中的<?php 与?>之间。




分享

62 条评论 - 我要发评论

  1. RachelSof

    The new XRumer 16.0 – revolution in online promotion:
    artificial intelligence will help you to attract customers so effectively,
    more than ever!

  2. KellyBer

    Hello, dear Administration!

    For a long time I watch your project,
    but today I was surprised strange facts (and photos) on your website,
    that someone posted on my profile:
    http://letsdodating.net/KellyBer/private_photo

    Is all this true?
    How to understand it all ?!
    I hope for early answer!

  3. AnnaMJ

    Hello! My name is AnnaMarkova, our company need to advertise on your website. What is your prices? Thank you. Best regards, Mary.

    1. 微而

      Are you sure ? Miss marry.This is just a personal website.

    2. 微而

      Oh,sorry.Is mary.

  4. 陶可佳

    :大眼: 有用的代码

报歉!评论已关闭.