两方法将WordPress评论作者链接隐藏采用Base64加密 减少导出权重

如果我们的网站注重SEO和权重的话,势必会对每一个导出的链接还是很重视的。我们要知道无论是内容中,甚至用户评论的导出链接都可能导致影响到我们网站权重。我们如果有用WordPress程序的肯定知道评论作者是可以有导出链接的,有很多人都是用故意来发布评论获取导出链接权重。

两方法将WordPress评论作者链接隐藏采用Base64加密 减少导出权重

考虑到用户体验互动的问题,我们禁止评论中加入链接稍显小气,但是我们如果可以将这个连接转换成跳转或者BASE64加密,那不影响互动,也当然不影响我们的网站权重被导出。这里有2个办法可以实现。

第一、直接代码方式

这里我们可以看到常见有一些网站是 "https://xxx.com/goto/base64加密连接"。

    function convert_to_internal_links($content){
        preg_match_all('/\shref=(\'|\")(http[^\'\"#]*?)(\'|\")([\s]?)/',$content,$matches);
        if($matches){
            foreach($matches[2] as $val){
                if(strpos($val,home_url())===false){
                    $rep = $matches[1][0].$val.$matches[3][0];
                    $new = '"'.home_url().'/goto/'.base64_encode($val).'" target="_blank"';
                    $content = str_replace("$rep","$new",$content);
                }
            }
        }
        return $content;
    }
    add_filter('the_content','convert_to_internal_links',99); // 文章正文外链转换
    add_filter('comment_text','convert_to_internal_links',99); // 评论内容的链接转换
    add_filter('get_comment_author_link','convert_to_internal_links',99); // 访客的链接转换
     
    function inlo_redirect() {
        $baseurl = 'goto';
        $request = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        $hop_base = trailingslashit(trailingslashit(home_url()).$baseurl); // 删除末尾的 斜杠/ 符号
        if (substr($request,0,strlen($hop_base)) != $hop_base)    return false;
        $hop_key = str_ireplace($hop_base, '', $request);
        if(substr($hop_key, -1) == '/')$hop_key = substr($hop_key, 0, -1);
        if (!empty($hop_key)) {
            $url = base64_decode($hop_key);
            wp_redirect( $url, 302 );
            exit;
        }
    }
    add_action('template_redirect','inlo_redirect');

添加到当前主题Functions.php中。

第二、简易修改法

1、重新定义链接

    // 重定义评论者链接-加密并添加nofollow
    function redefine_comment_author_link() {
        $encodeurl = get_comment_author_url( $comment_ID );
        $url = get_option('home').'/jv?url=' . base64_encode($encodeurl);//jv?url 自己修改,下面对应修改$_GET['url']中的url
        $author = get_comment_author( $comment_ID );
        if ( empty( $encodeurl ) || 'http://' == $encodeurl )
            return $author;
        else
            return "<a href='$url' rel='external nofollow' class='url'>$author</a>";
    }
    add_filter('get_comment_author_link', 'redefine_comment_author_link');

2、定义跳转样式

    function redirect_comment_link(){ // 重定向评论者链接
        $redirect = base64_decode($_GET['url']); // 解密GET获得的加密链接部分
        if($redirect){
            if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
            header("Location: $redirect");
            exit;
            } else {
            header("Location: http://www.itbulu.com/");//修改成你自己的地址
            exit;
            }
        }
    }
    add_action('init', 'redirect_comment_link');

这里我们恶意设置实时跳转。如果非跳转链接直接跳转到首页。

本文出处:老蒋部落 » 两方法将WordPress评论作者链接隐藏采用Base64加密 减少导出权重 | 欢迎分享( 公众号:老蒋朋友圈 )

公众号 「老蒋朋友圈」获取站长新知 / 加QQ群 【1012423279】获取商家优惠推送