[Resolved] Remove Author Link from Comments

Home Forums Support [Resolved] Remove Author Link from Comments

Home Forums Support Remove Author Link from Comments

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1604190
    Jesse

    Hello,

    I added the following code to my child theme functions.php, which did a great job at removing the author link in the comments section, but it also removed the reply link. I would like to keep the reply link. Can this code be updated to keep the reply link?

    https://gist.github.com/generatepress/6a9ad4e007ae0a7388bbbbb7b3ae068f

    Best regards,
    Jesse

    #1604471
    Elvin
    Staff
    Customer Support

    Hi,

    You can change your code to match this file’s Line 12 to Line 93. (This is the default comments.php file)
    https://github.com/tomusborne/generatepress/blob/master/inc/structure/comments.php#L12

    You then change get_comment_author_link() to match what you did on your code by replacing it with get_comment_author().

    Note: You should be using template files for this instead of functions.php for good housekeeping.

    A wise man once said:
    "Have you cleared your cache?"

    #1604777
    Jesse

    Hello,

    I’m sorry, I’m not understanding your message.

    I’m using this comments.php file (not the default comments.php file) in my child’s theme folder, which was used to move the comment form above the comments:

    https://docs.generatepress.com/article/move-the-comment-form-above-comments/

    And then I added this bit of code to my child’s functions.php file, which removed the author link as I wanted, but it also removed the reply link:

    https://gist.github.com/generatepress/6a9ad4e007ae0a7388bbbbb7b3ae068f

    So now, I just want to add the reply link back. Can you please let me know exactly what I need to do? Also, you mentioned something about using “template files” instead of the functions.php file. Can you clarify?

    Best regards,
    Jesse

    #1605685
    Elvin
    Staff
    Customer Support

    Use this on your child theme’s comments.php.

    https://gist.github.com/ejcabquina/76199e5139a0216507822b33382c9d51

    This code is directly taken from the default comments.php of the theme. I only changed get_comment_author_link() to get_comment_author() to remove the author link.

    I’ve also kept the do_action( 'generate_before_comment_text', $comment, $args, $depth );, add_action( 'generate_after_comment_text', 'generate_do_comment_reply_link', 10, 3 ); and the generate_do_comment_reply_link function to keep the default way of adding the reply link.

    A wise man once said:
    "Have you cleared your cache?"

    #1605716
    Jesse

    Hello,

    To recap, I was using this code for my comments.php to move the comment form above the comments (https://docs.generatepress.com/article/move-the-comment-form-above-comments/) plus this code in my functions.php to remove the author link which also removed the reply link (https://gist.github.com/generatepress/6a9ad4e007ae0a7388bbbbb7b3ae068f).

    I went ahead and removed the above code from my functions.php and then replaced my comments.php file with the one that you provided in your last message, but it caused a critical error on the website so I had to revert back.

    I’m still at square one. Can you please advise exactly what I need to do/change in order to add the reply link back?

    Best regards,
    Jesse

    #1605795
    Elvin
    Staff
    Customer Support

    I’m still at square one. Can you please advise exactly what I need to do/change in order to add the reply link back?

    If I may suggest a really simple solution:

    If the goal is solely to remove the comment author link, you can remove the gist code you’re using and simply strip its tags with a snippet so it displays as a text, not a link.

    function disable_comment_author_links( $author_link ){
    	return strip_tags( $author_link );
    }
    add_filter( 'get_comment_author_link', 'disable_comment_author_links' );

    This solution is short and simple. This doesn’t require you to use complicated code AND it doesn’t mess up the reply link. 🙂

    A wise man once said:
    "Have you cleared your cache?"

    #1605836
    Jesse

    Hello,

    I removed the Gist code that was in my functions.php and then added the snippet you provided above and it worked perfeclty. The reply link is back and the author name isn’t a link.

    Thanks!

    #1605883
    Elvin
    Staff
    Customer Support

    Glad you got it sorted. No problem. 🙂

    A wise man once said:
    "Have you cleared your cache?"

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