Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove rel=”nofollow” for admin only?

  • @jameshh93

    Participant

    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 5 replies - 1 through 5 (of 5 total)
  • @robin-w

    Moderator

    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

    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

    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

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

    @sirlouen

    Participant

    Hey @robin-w Tested but not working 🙁
    What can be failing in your idea?

    This doesn’t work either 🙁

    Remove NoFollow from BBPress Posts

    Will have to review the code and what’s going on with that filter nowadays

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