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.本站所有源码支持免费互换,所有资源来源于网络,分享目的仅供大家学习和交流!不得使用于非法商业用途,不得违反国家法律。否则后果自负!(下载即表示同意遵守此条例!) 所有资源,不能保证完全去除后门和源码的完整性!(建议先用D盾 等查杀软件先扫描一遍!)且都不包含技术服务请大家谅解!
2.根据二○○二年一月一日《计算机软件保护条例》规定:为了学习和研究软件内含的设计思想和原理, 通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可, 不向其支付报酬!鉴于此,也希望大家按此说明研究!
3.本站所有源码均收集来源于网络,若此源码资源等文章侵犯您的合法权益,请私信联系站长,并于24小时内删除下架。
4.本站所有源码仅限学习,交流使用,请勿上线或非法使用,一切法律责任均于此站无关。
5.侵权联系邮箱:188773464@qq.com
6.若您最终确认购买,则视为您100%认同并接受以上所述全部内容。

源码下载网 空间/建站/源码 wordpress插件/WordPress SEO插件推荐:Nofollow for external link开心无限制 https://svipm.com.cn/9758.html

相关文章

猜你喜欢