[Resolved] Change comment text and create anchor link to "Leave a comment"

Home Forums Support [Resolved] Change comment text and create anchor link to "Leave a comment"

Home Forums Support Change comment text and create anchor link to "Leave a comment"

  • This topic has 19 replies, 5 voices, and was last updated 5 years ago by Tom.
Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #663784
    Gian

    Hi,

    in my blog I have articles with over 400 comments (see url attached), for this reason I would like to create an anchor link that, when clicked, goes to the “Leave a comment” section.

    The anchor link should be placed at the end of the article after the text “430 comments on (article title). <a href="#anchorlink">New comment</a>" .

    Do you know how I can implement this option?

    Thank you in advance

    #663828
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You could use a Hook element in our Elements module.

    Add a new hook and give it this content:

    <a href="#respond">Leave a comment</a>

    Then add to the after_content hook.

    Then in Display Rules you can set it to only display in single posts.

    Hope this helps 🙂

    #663912
    Gian

    Thank you!

    What if I’d like to place the anchor link after the text “430 comments… Leave a comment” only when there is at least 1 comment on single posts?

    #664153
    David
    Staff
    Customer Support

    Hi there,

    you would need the below_comments_title hook – this is very useful:

    https://docs.generatepress.com/article/hooks-visual-guide/#single-post

    #664493
    Gian

    Hi David,

    Excellent, thank you!

    What if I’d like to give the anchor link the same styling as the other links of my website?

    Also, is there a simple way to change the text “Leave a comment on…” and remove the post title?

    #664590
    Tom
    Lead Developer
    Lead Developer

    Right now it’s a bit of a pain to change that text.

    I added a filter in GP 2.2 which will make it much easier: https://github.com/tomusborne/generatepress/commit/28d3c2acd7685e053e1f4f0baf442dffb966b5bb

    You can make the above change to your comments.php file to take advantage of it right now if you’d like:

    add_filter( 'generate_comment_form_title', function() {
        return 'Leave a comment';
    } );
    #664726
    Gian

    Ok, thank you 🙂

    #664774
    Tom
    Lead Developer
    Lead Developer

    No problem! 🙂

    #677009
    Paul

    Hi – I also want to remove the post title from this text, but don’t really understand what I need to do to achieve this. Please could you elaborate a little on the above.

    #677316
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    As of right now you’d need to edit the comments.php file: https://github.com/tomusborne/generatepress/commit/28d3c2acd7685e053e1f4f0baf442dffb966b5bb

    The red is what we removed, and the green is what we added. Note that if you copy/paste, you’ll need to remove the + characters from the start of each line.

    Then you’ll be able to use the function I posted above to change the message.

    #678971
    Paul

    That worked Thanks

    #679357
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

    #856988
    Iván

    Hi, Tom:

    I made what you explained to create an anchor link to “Leave a Comment”. The problem is that my anchor link doesn´t redirect me anywhere. Could you explain to me what am I doing wrong, please? http://lasimplicite.es

    Otherwise, how can I style the link? I would like it to be right aligned and with another font.

    Thank you very much!!

    #857413
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    What functions are you using to alter the link?

    #857695
    Iván

    Hi Tom,

    I have used a Hook element in your Elements module.
    I have added a new hook and give it this content: <a href="#respond">Leave a comment</a>
    Then I have added it to the after_content hook.
    Then in Display Rules I have set it to only display in single posts.

    That´s all! Sorry for my lack of knowledge…

    Thanks!!

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