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 12 replies - 1 through 12 (of 12 total)

  • jameshh93
    Participant

    @jameshh93

    Iv been searching around everywhere and cannot seem to find any solution for this? ๐Ÿ™
    Looks like this is something to do with it

    wp_rel_nofollow_callback() – Callback to add rel=nofollow string to HTML A element.


    jameshh93
    Participant

    @jameshh93

    Or if not how can I just turn off the rel nofollow for all users then?

    Posted on Bbpress forums and looks as though the solution provided their for getting rid of nofollow seem to get ignored when buddypress activated see link to forum thread

    Remove rel=โ€nofollowโ€ for admin only?


    jameshh93
    Participant

    @jameshh93

    I have now tried just adding

    remove_filter( ‘bp_activity_post_update’, ‘bp_activity_make_nofollow_filter’ );

    but that didnt work ๐Ÿ™

    Hi @jameshh93-

    You’ll have to make sure that you’re removing the action _after_ it’s been added, which is when the activity component is loaded.

    Here’s a handy list of BP startup actions: https://codex.buddypress.org/developer/buddypress-action-hook-sequence-during-startup/

    I’d probably try something around the bp_loaded action, like this:

    
    add_action( 'bp_loaded', function() {
        remove_filter( 'bp_activity_post_update', 'bp_activity_make_nofollow_filter' );
    } );
    

    Also, I’m not sure you’re targeting the right action. The nofollow filter is applied in these cases:

    
    add_filter( 'bp_get_activity_content',               'bp_activity_make_nofollow_filter' );
    add_filter( 'bp_get_activity_content_body',          'bp_activity_make_nofollow_filter' );
    add_filter( 'bp_get_activity_parent_content',        'bp_activity_make_nofollow_filter' );
    add_filter( 'bp_get_activity_latest_update',         'bp_activity_make_nofollow_filter' );
    add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
    add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
    

    the get_content action I’d probably try first is bp_get_activity_content_body when the activity is generated for display.


    jameshh93
    Participant

    @jameshh93

    @dcavins thank you for your reply I really do appreciate you taking time to help me!

    โ€‹
    For me this doesn’t seem to be working when I create an update with an url

    
    
    add_action( 'bp_loaded', function() {
    
        remove_filter( 'bp_get_activity_content',               'bp_activity_make_nofollow_filter' );
    
    remove_filter( 'bp_get_activity_content_body',          'bp_activity_make_nofollow_filter' );
    
    remove_filter( 'bp_get_activity_parent_content',        'bp_activity_make_nofollow_filter' );
    
    remove_filter( 'bp_get_activity_latest_update',         'bp_activity_make_nofollow_filter' );
    
    remove_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
    
    remove_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
    
    } );

    โ€‹

    โ€‹


    jameshh93
    Participant

    @jameshh93

    Tried just about every combination I can think of and still cannot seem to get rel”nofollow” removed let alone get it to just be removed for admin/editor roles ๐Ÿ™

    Honestly, I’m not sure why you’d want to remove the nofollow rel. It’s (supposed to be) used by search engine crawlers and doesn’t affect the experience of a web site visitor, as far as I understand.
    https://support.google.com/webmasters/answer/96569?hl=en


    jameshh93
    Participant

    @jameshh93

    I know what your saying but I like having full editorial control of my site and don’t want links posted by admins(me) being nofollowed if they are directed to sites that I own. Also if an accredited user who posts useful content posts a good link surely that link should be rewarded?

    ๐Ÿ™‚


    jameshh93
    Participant

    @jameshh93

    is there a way I can edit/overwrite “bp_activity_make_nofollow_filter_callback” and change the rel=”nofollow” text replace to replace with blank?


    jameshh93
    Participant

    @jameshh93

    Okay I have managed to get it to work for new activity posts however when admin makes comment with link it appears nofollow? How can I make this code work for activity comments replies too? thank you!

    โ€‹

    
    
    function rm_nofollow($txt) {
    
        $user_id = bp_get_activity_user_id( $activity_id ) ;
    
        $user_meta=get_userdata($user_id);
    
        $user_roles=$user_meta->roles;
    
        $allowed_roles = array('editor', 'administrator');
    
          if( array_intersect($allowed_roles, $user_roles ) ) { 
    
                $txt=str_replace(' rel="nofollow"','',$txt);
    
        }   
    
        return $txt;
    
    }
    
    add_filter('bp_get_activity_content','rm_nofollow',20);
    
    add_filter('bp_get_activity_content_body','rm_nofollow',20);
    
    add_filter('bp_get_activity_parent_content','rm_nofollow',20);
    
    add_filter('bp_get_activity_latest_update','rm_nofollow',20);
    
    add_filter('bp_get_activity_latest_update_excerpt','rm_nofollow',20);
    
    add_filter('bp_get_activity_feed_item_description','rm_nofollow',20);
    
    add_filter('bp_get_activity_feed_item_description','rm_nofollow',20);
    
    

    jameshh93
    Participant

    @jameshh93

    If user makes a comment on an admins comments then it appears without nofollow which I want but when comment made on activity comment from non admin comment link appears with a nofollow which im guessing because getting to the role in the if statement from the activity id rather than the comment id? How can I fix this to work for both main activity updates and comments?

    Also the way im doing it probably isnt very fast because buddypress is adding the nofollow and then all im doing is search and removing the nofollow every single time :/


    jameshh93
    Participant

    @jameshh93

    function rm_comment_nofollow($txt) {
    
        $user_id = bp_get_activity_comment_user_id($comment_ID) ;
    
        $user_meta=get_userdata($user_id);
    
        $user_roles=$user_meta->roles;
    
        $allowed_roles = array('editor', 'administrator');
    
        if( array_intersect($allowed_roles, $user_roles ) ) { 
    
             $txt=str_replace(' rel="nofollow"','',$txt);
    
        }
    
    return $txt;
    
    }

    For example using along side other function code found above that I am currently using works but only if admin/editor posts on an admin editor activity comment ๐Ÿ™ :/ ๐Ÿ˜ฎ

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