建站教程

建站教程

Products

当前位置:首页 > 建站教程 >

实战SEO优化策略建议3之LINKS超链接(WordPress自动给文章添加nofollow属性的实现方法)

GG网络技术分享 2025-03-18 16:14 0


实战SEO优化策略建议3之LINKS超链接

写上编文章时思路突然断片,今天补上。之前讲到第一条是网站集权问题,下面所讲到的基本上都和这条都有关系,那就是网站里的links超链接,分别有内链和外链(包括友链)。

内链、外链和友链

这里内链、外链和友链就不做解释了,内链要做到链接全部都统一更换为你自己配置的带www或不带www的集权域名链接。如果你网站页面有外链,要对外链a标签添加rel=\"nofollow\"属性,或者添加外链自动转内链代码,蜘蛛抓取时能有效防止分权。友链也是网站的常用功能,但是对于友链SEO做的不好的站点,只会拉低你的排名和权重,非要友链的话也可以使用外链方法处理,总之友链要慎重,而自己的子域名站点友链也要做到双向互链有去有回。

PHP外链转内链源码和使用方法(网友分享自行测试):

<html>

<head>

<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">

<title>页面加载中,请稍候...</title>

<style>

body{background:#000}.loading{-webkit-animation:fadein 2s;-moz-animation:fadein 2s;-o-animation:fadein 2s;animation:fadein 2s}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-o-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}.spinner-wrapper{position:absolute;top:0;left:0;z-index:300;height:100%;min-width:100%;min-height:100%;background:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:50%;left:50%;margin-left:-90px;margin-top: 2px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:36px;font-family:Arial}.spinner{position:absolute;top:50%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:25px solid rgba(100,100,100,0.2);-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;border-left-color:transparent;border-right-color:transparent;-webkit-animation:spin 1.5s infinite;-moz-animation:spin 1.5s infinite;animation:spin 1.5s infinite}@-webkit-keyframes spin{0%,100%{-webkit-transform:rotate(0deg) scale(1)}50%{-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin{0%,100%{-moz-transform:rotate(0deg) scale(1)}50%{-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin{0%,100%{-o-transform:rotate(0deg) scale(1)}50%{-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin{0%,100%{transform:rotate(0deg) scale(1)}50%{transform:rotate(720deg) scale(0.6)}}

</style>

</head>

<body>

<div class=\"loading\">

<div class=\"spinner-wrapper\">

<span class=\"spinner-text\">页面加载中,请稍候...</span>

<span class=\"spinner\"></span>

</div>

</div>

</body>

</html>

<?php

$URLs = $_SERVER[\"QUERY_STRING\"];

$URLs = urldecode($URLs);

if ($URLs == \'\'){

$URLs = \'http://www.360wifi.cc/\';

}

print ($URLs);//exit;

header(\"refresh:1;url=\".$URLs); // 1秒后跳转到传入地址

?>

1.把以上代码复制,另存为 go.php 放在指定的目录即可,跳转使用你的域名+你存放的目录+go.php?*

例如:http://www.360wifi.cc/bbkzy/go.php?https://www.baidu.com

2.最好在robots.txt中添加 Disallow:/bbkzy/go.php?* 代码即可屏蔽蜘蛛爬取跳转的外链。

当然还有很多实现方法这个功能,WordPress的程序可以使用插件也可以手动折腾代码,其他程序实现自行百度吧。

WordPress自动给文章添加nofollow属性的实现方法

本文实例讲述了WordPress自动给文章添加nofollow属性的实现方法。分享给大家供大家参考。具体分析如下:

nofollow属性是告诉搜索引擎不传权重过去,但WordPressk中如果我们要nofollow属性就需要手工加了,现在我来告诉大家利用 Nofollow for external link就可以自动给文章添加nofollow属性了.

直接安装启用 Nofollow for external link 插件,或者将下面的代码添加到当前主题的 functions.php 文件即可.

实例代码如下:

add_filter( \'the_content\', \'cn_nf_url_parse\');

function cn_nf_url_parse( $content ) {

$regexp = \"<as[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>\";
if(preg_match_all(\"/$regexp/siU\", $content, $matches, PREG_SET_ORDER)) {
if( !emptyempty($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 = \'/targets*=s*\"s*_blanks*\"/\';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= \' target=\"_blank\" \';
$pattern = \'/rels*=s*\"s*[n|d]ofollows*\"/\';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= \' rel=\"nofollow\" \';

$pos = strpos($url,$srcUrl);
if ($pos === false) {
$tag = rtrim ($tag,\'>\');
$tag .= $noFollow.\'>\';
$content = str_replace($tag2,$tag,$content);
}
}
}
}
$content = str_replace(\']]>\', \']]>\', $content);
return $content;
}

最终效果:自动给文章/页面的站外链接添加nofollow属性(rel=”nofollow”),并且在新窗口打开这些链接(即添加 target=”_blank”属性),如果已经手动给链接添加了 rel=”dofollow”,就不会添加 rel=”nofollow”,如果手动添加了 target=”_blank”,就不会重复添加.

为指定分类的所有链接添加nofollow属性,那你可以将下面的代码添加到主题的 functions.php 文件即可:

function nofollow_cat_posts($text) {
global $post;
if( in_category(1) ) { // 修改这里的分类ID
$text = stripslashes(wp_rel_nofollow($text));
}
return $text;
}
add_filter(\'the_content\', \'nofollow_cat_posts\');

希望本文所述对大家的WordPress建站有所帮助。

WordPress自动给文章添加nofollow属性的实现方法 (https://www.wpmee.com/) WordPress使用教程 第1张

标签:

提交需求或反馈

Demand feedback