-
ravisaive
Hello Support,
I’m interested in implementing a breadcrumb and meta tags similar to the one shown in this image: [https://postimg.cc/KKyxXHwS].
Additionally, I’d like to display the comment count with the text “Leave a reply” as depicted in this image: [https://postimg.cc/7CyGBXNb].
Also, I want to add a comment pagination as shown in this image [https://postimg.cc/GBcYLqTV].
Thank you.
-
Alvind
Hi there,
GeneratePress doesn’t have built-in breadcrumbs, but if you’re using Yoast, here’s a documentation to add one:
https://docs.generatepress.com/article/adding-breadcrumbs/To display the comment count, we can use a Block Element to show it above the comment section. We just need to create a shortcode to fetch and display the total comments of the current post.
First, add this PHP code:
function add_comments($atts, $content = null) { ob_start(); do_action('comments_number'); return ob_get_clean(); } add_shortcode('get_comments_num', 'add_comments'); add_action('comments_number', function(){ echo '<p>' . get_comments_number() . ' comments' . '</p>'; }, 10);
This snippet will create the
[get_comments_num]
shortcode to output the comment count of a post.Next, create a new Element > Block. Add a container and place two GB Heading blocks inside the container, following this structure:
-Container --Headline Block 1 (comment count) --Headline Block 2 (Leave a reply text)
Select the container, go to Block settings, and under Layout, set the DISPLAY to
Flex
and JUSTIFY CONTENT tospace-between
.In Headline Block 1, add
[get_comments_num]
as the text to render the comment count on the frontend.On the right side, in the Element settings, set Element Type to Hook and Hook Name to
before_comments_container
.For the location, set it to Posts > All posts.
Regarding comment pagination, unfortunately, GeneratePress doesn’t handle that directly. However, you may find some ways to achieve it in this forum topic:
https://generatepress.com/forums/topic/how-to-show-comment-pagination/ -
ravisaive
Hi Alvind,
I’m currently using All-In-One-SEO. Do you have any documentation available for implementing breadcrumbs with it?
I’ve added the PHP code and created the block accordingly, but it’s not displaying properly. I believe I need some CSS adjustments for it (could you provide CSS).
Please take a look at the screenshot here: [https://postimg.cc/S2DPqCWq].
Additionally, I’d like to include a comment icon, and I want the text “Leave a reply” to be a clickable link that directs users to the comment form when clicked.
Thank you.
-
The All In One SEO plugin provides this documentation on Breadcrumbs:
https://aioseo.com/docs/displaying-breadcrumbs-on-your-site/
Looks like they provide a few options for displaying them including shortcodes, blocks and PHP
You can use a GP Hook Element in the
generate_before_entry_title
Hook to add the shortcode before the title.For the Comments title, remove what code Alvind provided and the element and instead add this PHP Snippet:
add_filter( 'generate_comment_form_title', function() { $comments_number = get_comments_number(); return sprintf( // WPCS: XSS OK. /* translators: 1: number of comments */ esc_html( _nx( '%1$s comment', '%1$s comments', $comments_number, 'comments title', 'generatepress' ) ), number_format_i18n( $comments_number ) ); } ); add_filter( 'generate_comments_title_output', function( $output, $comments_title, $comments_number ) { $reply = '<a href="#reply-title">Leave a Reply</a>'; $output = '<div class="comment-title-wrap">' . $output . $reply . '</div>'; return $output; }, 10, 3 );
This will replace the default comment reply with that content.
Then add this CSS to format it:.comment-title-wrap { display: flex; align-items: baseline; justify-content: space-between; } .comments-title, .comment-title-wrap a { font-size: 20px; font-weight: 700; text-decoration: none; color: #000; }
-
ravisaive
Hello David,
Thank you, the code is functioning properly. The only additional request I have is if you could provide the CSS for the comment icon and a button CSS for the “Leave a reply” section, similar to the ones shown in this image – https://postimg.cc/7CyGBXNb.
-
Alvind
Update David’s CSS to this:
.comment-title-wrap { display: flex; align-items: baseline; justify-content: space-between; } .comments-title, .comment-title-wrap a { font-size: 16px; font-weight: 600; text-decoration: none; color: #000; } .comment-title-wrap a { border-radius: 5px; padding: 8px; background-color: #e0e0e0; } .comments-title::before { content: url('https://svgshare.com/i/15Xe.svg'); display: inline-block; margin-right: 10px; vertical-align: middle; }
-
ravisaive
Thank you, @David and @Alvind,
The CSS code is working properly… 🙂
I have a few additional requirements…
I’d like to include a meta tag on individual post pages, similar to what’s shown in this image [https://postimg.cc/KKyxXHwS].
For instance, it should appear like this:
Last Updated on April 19th, 2024 by the Author | Reviewed by the Author | 10 Comments
Also, any tips or documentation for adding comment pagination like this [https://postimg.cc/GBcYLqTV]
-
Alvind
To customize the post meta, the easiest way would be to use the Block Element – Post Meta Template:
https://docs.generatepress.com/article/block-element-post-meta-template/Regarding the comment pagination, you can refer to this topic for some tips:
https://generatepress.com/forums/topic/pagination-for-comments-with-page-numbers-in-generate-press/
- You must be logged in to reply to this topic.