• Resolved ajtatum

    (@ajtatum)


    I’m using ahrefs to perform site audits, and it’s constantly complaining about duplicate content because it finds its way to the site’s login page in the “Leave a Comment” section of a blog post. The text reads “You must be logged in to post a comment.” where “logged in” links to the login page. I was curious if there was a way to make it so that the link is nofollow.

    Any suggestions would be greatly appreciated!

    Thanks,
    AJ

    • This topic was modified 3 years, 4 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 2 replies - 1 through 2 (of 2 total)
  • I inspected the “logged in” link element on the Twenty Twenty One theme and found that its containing paragraph has the class “must-log-in.” I searched WordPress core for that and came across a $defaults array holding the link tag “must_log_in” as well as an opportunity to filter the $defaults array.

    This code adds rel=”nofollow” for the Twenty Twenty One theme on my local install. I’m hoping it will have the same effect in your situation. You can add this to your functions file or use the Code Snippets plugin.

    add_filter('comment_form_defaults', 'wpsf_logged_in_nofollow');
    function wpsf_logged_in_nofollow($defaults)
    {
    	$defaults['must_log_in'] = str_replace('a href', 'a rel="nofollow" href', $defaults['must_log_in']);
    	return $defaults;
    }
    Thread Starter ajtatum

    (@ajtatum)

    Wow, thank you @rickymccallum87! That worked perfectly for me though I’m not using the default theme. I sincerely appreciate it!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make login link in “Leave a Comment” nofollow?’ is closed to new replies.