• Resolved Bike Gremlin

    (@bikegremlin)


    Not 100% sure this is the right place to ask, but I hope to be (re)directed in case it isn’t:

    Is there a way to make links posted in WordPress comments do-follow (instead of the default nofollow)? Without using another plugin just for that – but by using custom code with a child theme.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    This might help: https://wordpress.stackexchange.com/a/275791

    Let me know ??

    Thread Starter Bike Gremlin

    (@bikegremlin)

    From testing on one site – deleted cache on the server, Cloudflare cache and browser cache – didn’t work. Will Google more.

    Since it’s probably not related to any particular theme, I’m marking it as resolved. Though any help or advice is welcome.

    Will give feedback when/if I figure it out.

    Theme Author Tom

    (@edge22)

    Strange, it looks like it should work:

    remove_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 );

    How are you adding it to your site?

    Thread Starter Bike Gremlin

    (@bikegremlin)

    Using a child theme.
    In the functions.php of the child theme.

    Thread Starter Bike Gremlin

    (@bikegremlin)

    EDIT: nope, doesn’t help either. ??
    Early to cheer.

    This seems to do the trick, in case it helps anyone else:

    // BEGIN remove nofollow from links in comments

    add_filter( ‘comment_text’, ‘remove_rel_nofollow_attribute’ );
    function remove_rel_nofollow_attribute( $comment_text ) {
    $comment_text = str_ireplace(‘ rel=”nofollow”‘, ”, $comment_text );
    return $comment_text;
    }

    // END remove nofollow from links in comments

    • This reply was modified 4 years, 6 months ago by Bike Gremlin.
    Theme Author Tom

    (@edge22)

    Yea, I found that one too but wasn’t sure it would work.

    If you’d like to link me to a comment where I can see a nofollow attribute, I can tweak that function so it will work.

    Let me know ??

    Thread Starter Bike Gremlin

    (@bikegremlin)

    Here’s an example:

    https://bicikl.bikegremlin.com/1007/koji-tip-bicikla-odgovara-za-moje-potrebe/#comment-1543

    Sometimes it’s rel=”nofollow”, sometimes rel=”nofollow ugc”, sometimes added the options for opening it in a separate tab (noopener…).

    Theme Author Tom

    (@edge22)

    You may need to alter it for each case:

    add_filter( 'comment_text', function( $text ) {
        $comment_text = str_replace( ' rel="nofollow"', '', $comment_text );
        $comment_text = str_replace( ' rel="nofollow ugc"', ' rel="ugc"', $comment_text );
    
        return $comment_text;
    } );
    Thread Starter Bike Gremlin

    (@bikegremlin)

    Thanks – will give it a go and see how it goes. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Do follow comments’ is closed to new replies.