Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove rel=”nofollow” for admin only?


  • jameshh93
    Participant

    @jameshh93

    It makes little sense to set nofollow links on my site from trusted members. Is there a quick functions.php fix that will remove the no follow tag on external links for accounts who have admin or editor status only?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)

  • Robin W
    Moderator

    @robin-w

    the no follow is added at output, not on saving.

    so we need to see if the topic/reply is written by an admin or editor and then remove the filter that does the no-follow

    This coded is untested, but should work

    
    add_filter ('bbp_get_topic_content' , 'follow_topic_if_admin' , 10 , 2) ;
    
    function follow_topic_if_admin ($content, $topic_id) {
    	$user_id = bbp_get_topic_author_id( $topic_id ) ;
    	$user_meta=get_userdata($user_id);
    	$user_roles=$user_meta->roles;
    	$allowed_roles = array('editor', 'administrator');
    	if( array_intersect($allowed_roles, $user_roles ) ) { 
    		remove_filter( 'bbp_get_topic_content', 'bbp_rel_nofollow',   50   );
    	}
    return apply_filters( 'follow_topic_if_admin', $content, $topic_id );
    }
    
    add_filter ('bbp_get_reply_content' , 'follow_reply_if_admin' , 10 , 2) ;
    
    function follow_reply_if_admin ($content, $reply_id) {
    	$user_id = bbp_get_reply_author_id( $reply_id ) ;
    	$user_meta=get_userdata($user_id);
    	$user_roles=$user_meta->roles;
    	$allowed_roles = array('editor', 'administrator');
    	if( array_intersect($allowed_roles, $user_roles ) ) { 
    		remove_filter( 'bbp_get_reply_content', 'bbp_rel_nofollow',   50   );
    	}
    return apply_filters( 'follow_reply_if_admin', $content, $reply_id );
    }

    Add this to your functions file.

    Let me know if it works


    jameshh93
    Participant

    @jameshh93

    Thank you, unfortunately just tested it creating a new users with for both admin and editor roles and posting a reply with a link and the nofollow is still there 🙁


    jameshh93
    Participant

    @jameshh93

    Could it be that I have Buddypress activated as well?

    Buddypress has this “wp_rel_nofollow_callback() – Callback to add rel=nofollow string to HTML A element.”

    *Wouldn’t mind also being able to disable nofollow links for admins on buddypress too.


    Robin W
    Moderator

    @robin-w

    may well be. you’ll need to post on the buddypress support site for help – I know little of buddypress !

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.