最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to change all external links to "nofollow" but only by user role

programmeradmin4浏览0评论

I am looking for this question How can I nofollow all external links by user role? I have found these codes to convert all links to Nofallow, can anyone change these codes according to the user's role /

// add nofollow to links
function nofollow_for_external($content) {
    $content = preg_replace_callback( '/<a[^>]*href=["|\']([^"|\']*)["|\'][^>]*>([^<]*)<\/a>/i', function($m) {
     if (strpos($m[1], "domain") === false)
          return '<a href="'.$m[1].'" rel="nofollow">'.$m[2].'</a>';
     else
         return '<a href="'.$m[1].'">'.$m[2].'</a>';
     },
     $content );
     return $content;
 }
 add_filter('the_content', 'nofollow_for_external');
// Stop self pingback
function disable_self_ping( &$links ) {
    $home = get_option( 'home' );
    foreach ( $links as $l => $link )
        if ( 0 === strpos( $link, $home ) )
            unset($links[$l]);
}
add_action( 'pre_ping', 'disable_self_ping' );
发布评论

评论列表(0)

  1. 暂无评论