admin管理员组文章数量:1391975
I would like to know how I can set all external links in all posts from a certain wordpress user in my blog automatically to "nofollow" ? So that old postings and future postings from this user are affected by this "nofollow" command. How is that possible?
Thank you so much!
I would like to know how I can set all external links in all posts from a certain wordpress user in my blog automatically to "nofollow" ? So that old postings and future postings from this user are affected by this "nofollow" command. How is that possible?
Thank you so much!
Share Improve this question asked Feb 16, 2020 at 7:56 Patrick DreidPatrick Dreid 317 bronze badges1 Answer
Reset to default 1You want to try something like this (untested):
// Nofollow in content
$author_id = get_the_author_meta( 'ID' );
add_filter('the_content', 'my_nofollow');
function my_nofollow($content) {
//return stripslashes(wp_rel_nofollow($content));
return preg_replace_callback('/<a[^>]+/', 'my_nofollow_callback', $content);
}
function my_nofollow_callback($matches, $author_id) {
$link = $matches[0];
$site_link = get_bloginfo('url');
if ($author_id === 4) {
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) && (strpos($link, 'rel') === false)) {
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
}
}
return $link;
}
Note: This is based on a nofollow function I am using on one of my sites and I just added a conditional for if ( is_author () )
in there
本文标签: How to set all external links from a certain user to quotnofollowquot
版权声明:本文标题:How to set all external links from a certain user to "nofollow"? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744744214a2622791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论