-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Breadcrumbs: Add support for paginated post content #72905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breadcrumbs: Add support for paginated post content #72905
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
2159baf to
adaa408
Compare
|
Thanks for the PR @harshbhonsle! #72873 landed, so it would be great to rebase/adjust in order to review 😄 |
|
@ntsekouras @tyxla Quick question before merging: for posts that use |
The former as it should include the post title. |
adaa408 to
1c26227
Compare
|
Hi @ntsekouras I’ve implemented the changes for paginated post support in the Breadcrumbs block. I’m new to contributing, so please let me know if I’ve made any mistakes or if improvements are needed — I’m happy to update them! Here’s a quick preview of how it looks: |
| } | ||
| // Add current post title (not linked). | ||
| $breadcrumb_items[] = block_core_breadcrumbs_create_current_item( block_core_breadcrumbs_get_post_title( $post ), true ); | ||
| $title = get_the_title( $post ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the title we have the block_core_breadcrumbs_get_post_title helper function. We shouldn't remove it and see how it fits with the new helper functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m keeping the current line:
$breadcrumb_items[] = block_core_breadcrumbs_create_current_item(
block_core_breadcrumbs_get_post_title( $post ),
true
);
This handles the current post title as before. The new logic I’m adding for paginated posts (Page X) would come after this line so that the breadcrumb shows both the post title and the page number.
Does that approach look good to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier if you make the changes make reviewing/testing easier.
In general the flow would be to check if is paged and either call block_core_breadcrumbs_create_item or inline the logic there to work for the page query var, as I'm not sure if get_pagenum_link will handle it properly (I think it handles paged query var).
So if is paged -> block_core_breadcrumbs_create_link -> add the Page X item.
If not paged -> you call the existing line in trunk with block_core_breadcrumbs_create_current_item.
Does this help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I’ve implemented it as suggested: the current post title is always added as a non-linked item, and if the post is paginated, a “Page X” item is appended. Changes have been pushed for review/testing.
| * @param array $breadcrumb_items Array of existing breadcrumb items. | ||
| * @return array Modified breadcrumb items including "Page X" if needed. | ||
| */ | ||
| function block_core_breadcrumbs_maybe_add_paged( $breadcrumb_items ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has been removed and we have new helper functions since this PR. We should see what we can use in this case, but given the query param is different for pages (page), it might even not need new helper functions and we could possibly inline the logic (last else block in the main render_block_core_breadcrumbs function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ntsekouras
I’ve implemented the inline logic for paginated post content directly in the else block after the post title — instead of using the removed block_core_breadcrumbs_maybe_add_paged() function.
It checks get_query_var( 'page' ) and adds a “Page X” breadcrumb when greater than 1:
$page_number = max( 1, get_query_var( 'page' ) );
if ( $page_number > 1 ) {
/* translators: %d: current page number. */
$breadcrumb_items[] = block_core_breadcrumbs_create_current_item(
sprintf( esc_html__( 'Page %d', 'gutenberg' ), number_format_i18n( $page_number ) ),
true
);
}
Could you please confirm if this approach looks good before I commit and push the changes?
e00e804 to
6ce5e3a
Compare
| } | ||
| // Add current post title (not linked). | ||
| $breadcrumb_items[] = block_core_breadcrumbs_create_current_item( block_core_breadcrumbs_get_post_title( $post ), true ); | ||
| $breadcrumb_items[] = block_core_breadcrumbs_create_current_item( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is close, but we should also handle the case where is paged. When it is, we should create a link.
I think the below code would be enough:
$is_paged = (int) get_query_var( 'page' ) > 1;
$title = block_core_breadcrumbs_get_post_title( $post );
if ( $is_paged ) {
$breadcrumb_items[] = block_core_breadcrumbs_create_link( get_permalink( $post ), $title, true );
$breadcrumb_items[] = block_core_breadcrumbs_create_page_number_item( 'page' );
} else {
$breadcrumb_items[] = block_core_breadcrumbs_create_current_item( $title, true );
}
For that to work though, we'll need another small change in block_core_breadcrumbs_create_page_number_item to pass the query_var like this:
function block_core_breadcrumbs_create_page_number_item( $query_var = 'paged' ) {
$paged = (int) get_query_var( $query_var );
return block_core_breadcrumbs_create_current_item(
/* translators: %s: page number */
sprintf( __( 'Page %s' ), number_format_i18n( $paged ) )
);
}
ntsekouras
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Let's get this in.
|
Hi @ntsekouras, thank you for your guidance throughout the breadcrumbs pagination PR. Your feedback on the page query var, post title linking, and helper logic was incredibly helpful. As my first Gutenberg feature contribution, your clear explanations — especially around when to inline logic vs. rely on helpers — really helped me understand the Breadcrumbs block internals and workflow. I appreciate you reviewing each iteration. Thanks again for your support and for merging the PR — I’m excited to keep contributing and learning! |
|
Happy to help @harshbhonsle and thank you again for your time and effort to contribute! |



What?
Closes #72876
Adds support for paginated post content (split using
<!--nextpage-->or the Page Break block) in the Breadcrumbs block.Why?
Currently, the Breadcrumbs block does not indicate the current page when viewing paginated post content.
This enhancement adds a clear “Page X” breadcrumb, improving navigation clarity for long-form posts.
Example:
Home › Post TitleHome › Post Title / Page 2Home › Post Title / Page 3This aligns the Breadcrumbs block’s behavior with archive pagination.
How?
block_core_breadcrumbs_maybe_add_paged()that already handles archive pagination.pagedquery var)pagequery var)Testing Instructions
<!--nextpage-->)./my-post/→ should showHome / Post Title/my-post/2/→ should showHome / Post Title / Page 2/my-post/3/→ should showHome / Post Title / Page 3Screenshots or Screencast
Screenshots
Page Xfor paginated post views.