Archived topic
Change comment text and create anchor link to "Leave a comment"
19 replies · Started by Gianluca on August 29, 2018
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
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 :)
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?
Hi there,
you would need the below_comments_title hook - this is very useful:
https://docs.generatepress.com/article/hooks-visual-guide/#single-post
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?
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';
} );
Ok, thank you :)
No problem! :)
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.
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.
That worked Thanks
You're welcome :)
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!!
Hi there,
What functions are you using to alter the link?
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!!