wordpress插件/WordPress SEO插件推荐:Nofollow for external link开心无限制

[wordpress插件] WordPress SEO插件推荐:Nofollow for external link开心无限制版

给WordPress文章或评论内容的站外链接添加Nofollow属性,在博客里编写文章的时候都会用到一些外链,外链这个东西根据每个人对SEO的理解层面不同所以运用上也都有不同的手法,非常多的站长在使用wordpress发表文章带外链的文章时都会给外链添加nofollow属性。

方法1:直接安装插件即可,不想用插件的可以参考方法2
方法2:打开我们所用的主题的模板函数文件,也就是functions.php 文件,将下面的代码加到模板函数里面,它会给外部链接自动添加

代码如下:

// 在主题模板functions.php文件中添加
add_filter('the_content', 'auto_nofollow'); //nofollow文章内容的站外链接
add_filter('comment_text', 'auto_nofollow'); //nofollow评论内容的站外链接
function auto_nofollow($content) {
//return stripslashes(wp_rel_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;
}
// 在主题模板functions.php文件中添加
add_filter('the_content', 'auto_nofollow'); //nofollow文章内容的站外链接
add_filter('comment_text', 'auto_nofollow'); //nofollow评论内容的站外链接
function auto_nofollow($content) {
//return stripslashes(wp_rel_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;
}
// 在主题模板functions.php文件中添加
add_filter('the_content', 'auto_nofollow'); //nofollow文章内容的站外链接
add_filter('comment_text', 'auto_nofollow'); //nofollow评论内容的站外链接
function auto_nofollow($content) {
//return stripslashes(wp_rel_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;
}
// 在主题模板functions.php文件中添加
add_filter('the_content', 'auto_nofollow'); //nofollow文章内容的站外链接
add_filter('comment_text', 'auto_nofollow'); //nofollow评论内容的站外链接
function auto_nofollow($content) {
//return stripslashes(wp_rel_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;
}

// 在主题模板functions.php文件中添加

add_filter(‘the_content’‘auto_nofollow’); //nofollow文章内容的站外链接

add_filter(‘comment_text’‘auto_nofollow’); //nofollow评论内容的站外链接

function auto_nofollow($content) {

//return stripslashes(wp_rel_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’,

wordpress插件/WordPress SEO插件推荐:Nofollow for external link开心无限制

购买须知/免责声明
1.本文部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责。
2.若您需要商业运营或用于其他商业活动,请您购买正版授权并合法使用。
3.如果本站有侵犯、不妥之处的资源,请在网站右边客服联系我们。将会第一时间解决!
4.本站所有内容均由互联网收集整理、网友上传,仅供大家参考、学习,不存在任何商业目的与商业用途。
5.本站提供的所有资源仅供参考学习使用,版权归原著所有,禁止下载本站资源参与商业和非法行为,请在24小时之内自行删除!
6.不保证任何源码框架的完整性。
7.侵权联系邮箱:aliyun6168@gail.com / aliyun666888@gail.com
8.若您最终确认购买,则视为您100%认同并接受以上所述全部内容。

海外源码网 会员免费/建站模版源码 wordpress插件/WordPress SEO插件推荐:Nofollow for external link开心无限制 https://moyy.us/9758.html

相关文章