[Resolved] Remove comment author url link and comment date/time

Home Forums Support [Resolved] Remove comment author url link and comment date/time

Home Forums Support Remove comment author url link and comment date/time

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1553715
    Baz

    Hi guys, I want to remove the comment author’s url link from the comments section (not the comments form), and also the comments date/time. I could probably do this with CSS, but hopefully there’s a function somewhere!

    I would also like to add some text after the ‘Leave a Comment’ title e.g. “Your email address and website details will not be published”.

    Thanks.

    #1555381
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Unfortunately, the only way to do this without CSS is to overwrite the entire function responsible for displaying the comments: https://github.com/tomusborne/generatepress/blob/3.0.2/inc/structure/comments.php#L12-L91

    That’s not ideal, as you’d need to keep it updated if we change anything within it during an update.

    We can, of course, disable the links using CSS very easily.

    You should be able to change that text like this:

    add_filter( 'generate_leave_comment', function() {
        return 'Leave a Comment - Your email address and website details will not be published';
    } );

    Let me know 🙂

    #1555412
    Baz

    Hi Tom.

    I was able to change the ‘Leave a Comment’ text with your snippet. I can remove the date/time with CSS but having a little trouble targeting the author url. Any help/tips will be much appreciated.

    I normally use the Genesis theme which has a filter to remove the author url.

    Thanks.

    #1555623
    Leo
    Staff
    Customer Support

    Can you give this CSS a shot?

    .comment-author-info a {
        pointer-events: none;
        color: #000000;
    }
    #1555630
    Baz

    Worked perfectly! Thanks Leo 🙂

    #1555653
    Leo
    Staff
    Customer Support
    #1768623
    Charbel

    Hello @Leo and @Tom,

    Hope you are doing well.

    I came across the same request noted here. I have implemented the CSS code noted below.

    .comment-author-info a {
        pointer-events: none;
        color: #000000;
    }

    The author URL link and comment date/time got removed, however, Google PageSpeed Insights is still complaining about: Avoid an excessive DOM size for author URL and date and time.

    Example:
    Maximum DOM Depth
    April 23, 2021 at 1:59 pm
    <time datetime=”2021-04-23T13:59:43+02:00″ itemprop=”datePublished”>

    I was able to fix the author URL link by removing it completely using the following function:

    add_filter( 'get_comment_author_link', 'rv_remove_comment_author_link', 10, 3 );
    function rv_remove_comment_author_link( $return, $author, $comment_ID ) {
    	return $author;
    }

    However, I still need to do the same (remove only #hyperlink) for date/time as well.

    Could you please help with achieving that? (comments.php)

    Single post example here: https://charbelnemnom.com/sc-200-exam-study-guide-microsoft-security-operations-analyst/

    Your help is highly appreciated!

    Thank You!
    -Charbel

    #1770583
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m not seeing a hyperlink for date/time anywhere – can you point me in the right direction?

    A link isn’t going to trigger the Maximum DOM Depth problem – that only happens when you have a ton of elements nested inside each other (think page builders). Not sure how it applies here.

    #1770949
    Charbel

    Hello @Tom,

    Thank you for your kind reply!

    I took out / removed line 47 from the comments.php to remove the hyperlink for date/time from all comments. For this reason, you are not seeing the hyperlink anymore.

    https://github.com/tomusborne/generatepress/blob/3.0.3/inc/structure/comments.php#L47

    Then, I have added the following code in funtions.php to remove the Author hyperlink from all comments as well.

    add_filter( 'get_comment_author_link', 'rv_remove_comment_author_link', 10, 3 );
    function rv_remove_comment_author_link( $return, $author, $comment_ID ) {
    	return $author;
    }

    After I removed the Hyperlink for the date/time + author, Google PageSpeed insight is complaining now about:

    Maximum DOM Depth | Element (Author Name) <cite itemprop=”name” class=”fn”>. footer.comment-meta Line 43:

    https://github.com/tomusborne/generatepress/blob/3.0.3/inc/structure/comments.php#L43

    How to solve the Maximum DOM Depth for the comments section, please?

    I have another one for Maximum Child Elements that’s coming from JetPack Social media sharing option.

    Thank You Tom!
    -Charbel

    #1771539
    Tom
    Lead Developer
    Lead Developer

    We’ll be adding a filter to the output of that element so you can remove the link without altering core files in 3.1.0.

    The DOM thing could be the nested comments you have in that article – you can limit the depth of comment nesting in “Settings > Discussion”.

    #1771549
    Charbel

    Thank you @Tom for the update, much appreciated!

    Looking forward to the new filter update in 3.1.0. Is there any ETA on when this update will be released?

    In the meantime, I removed Enable threaded (nested) comments levels deep in “Settings > Discussion” to solve the DOM Elements.

    Many Thanks and keep up the good work!

    -Charbel

    #1772899
    Tom
    Lead Developer
    Lead Developer

    No ETA yet – it’s a big one!

    Glad that option helped 🙂

    #1772911
    Charbel

    Thank You @Tom!

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