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

2025-02-26 0 83,001

[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开心无限制

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

会员源码网 建站模版类 wordpress插件/WordPress SEO插件推荐:Nofollow for external link开心无限制 https://svipm.com/9758.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务