Skip to content

Conversation

@ntsekouras
Copy link
Contributor

What?

Part of: #72498

This PR adds the archive link if enabled in posts, as it seems like a good default to have for the breadcrumbs.

Testing Instructions

  1. Enable GB experimental blocks.
  2. For easier testing I'm adding this plugin and the core block in theme's header and test various pages in the front end.
  3. Test with custom post types with has_archive enabled and disabled.

Screenshots or screencast

Below I'm sharing some screenshots in a site that I've added @justintadlock's plugin and the core block in the main header.
Above is x3p0-breadcrumbs/ and below is the core block.

Product (Woo) with terms

Screenshot 2025-10-30 at 1 37 14 PM

CPT without terms

Screenshot 2025-10-30 at 1 37 24 PM

Hierarchical CPT with ancestors

Screenshot 2025-10-30 at 1 44 44 PM
return sprintf(
'<a href="%s">%s</a>',
esc_url( $archive_link ),
esc_html( $post_type_object->labels->name )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also the archives label, which I agree isn't necessarily that broadly used. I wonder if we considered if we want to go with that, potentially.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point! Actually it seems like something we should do, but I'd also like @justintadlock's thoughts since in his plugin it seems it doesn't use that (below is core block with archives label.
Screenshot 2025-10-31 at 11 40 36 AM

@github-actions
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

* @return array Array of breadcrumb HTML items.
*/
function block_core_breadcrumbs_get_hierarchical_post_type_breadcrumbs( $post_id ) {
function block_core_breadcrumbs_get_hierarchical_post_type_breadcrumbs( $post_id, $post_type ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels non-ergonomic that we also have to pass the post type explicitly. I'd rather grab it from the $post_id:

$post_type = get_post_type( $post_id );

In theory, it should be free to do that since the post object is already in the WP_Query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From one hand you're probably right because this block doesn't make much sense in blocks that update the block context manually (like Query Loop). On the other hand though why call another function (get_post_type) when we already have the info?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree if we had it inline, or if we didn't have it loaded from the database. But it should already be loaded, and we don't have it inline in that function either - we pass it between functions, and to do so we need to add an extra argument. This makes it less ergonomic, which is something to cosnider when designing functions and APIs.

That being said, I don't feel strongly about it, I don't think it's a major deal.

@github-actions
Copy link

Flaky tests detected in 5cac11c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18968754081
📝 Reported issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Breadcrumbs (experimental) Affects the Breadcrumbs Block [Type] Enhancement A suggestion for improvement.

3 participants