- This topic has 19 replies, 5 voices, and was last updated 5 years ago by Tom.
-
AuthorPosts
-
August 29, 2018 at 6:11 pm #663784Gian
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
August 29, 2018 at 7:36 pm #663828TomLead DeveloperLead DeveloperHi 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 🙂
August 29, 2018 at 11:00 pm #663912GianThank 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?
August 30, 2018 at 4:36 am #664153DavidStaffCustomer SupportHi there,
you would need the
below_comments_title
hook – this is very useful:https://docs.generatepress.com/article/hooks-visual-guide/#single-post
August 30, 2018 at 8:53 am #664493GianHi 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?
August 30, 2018 at 10:34 am #664590TomLead DeveloperLead DeveloperRight 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'; } );
August 30, 2018 at 1:35 pm #664726GianOk, thank you 🙂
August 30, 2018 at 3:24 pm #664774TomLead DeveloperLead DeveloperNo problem! 🙂
September 14, 2018 at 3:23 am #677009PaulHi – 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.
September 14, 2018 at 9:17 am #677316TomLead DeveloperLead DeveloperHi 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.
September 17, 2018 at 1:26 am #678971PaulThat worked Thanks
September 17, 2018 at 8:45 am #679357TomLead DeveloperLead DeveloperYou’re welcome 🙂
April 2, 2019 at 7:29 am #856988IvánHi, 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!!
April 2, 2019 at 3:59 pm #857413TomLead DeveloperLead DeveloperHi there,
What functions are you using to alter the link?
April 3, 2019 at 1:35 am #857695IvánHi 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!!
-
AuthorPosts
- You must be logged in to reply to this topic.