Skip to content

Conversation

@ntsekouras
Copy link
Contributor

@ntsekouras ntsekouras commented Oct 30, 2025

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.

CPT with terms

Screenshot 2025-11-17 at 9 21 49 AM

CPT without terms

Screenshot 2025-11-17 at 9 24 45 AM

Hierarchical CPT with ancestors

Screenshot 2025-11-17 at 9 26 00 AM

@github-actions
Copy link

github-actions bot commented Oct 31, 2025

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 <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: mcsf <[email protected]>

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

github-actions bot commented Oct 31, 2025

Flaky tests detected in 4869547.
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/19099291596
📝 Reported issues:

@ntsekouras ntsekouras force-pushed the breadcrumbs/add-archive-link-if-enabled-in-posts branch from 5cac11c to 2b42e7f Compare November 5, 2025 10:35
@ntsekouras ntsekouras force-pushed the breadcrumbs/add-archive-link-if-enabled-in-posts branch from 4869547 to 36fd1fa Compare November 17, 2025 07:21
@ntsekouras ntsekouras force-pushed the breadcrumbs/add-archive-link-if-enabled-in-posts branch 2 times, most recently from 04253f0 to 556af36 Compare November 17, 2025 13:32
Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for accommodating!

There's just one thing that should be quickly addressable before merging:

Image

Displaying both "Home" and "Post Archives" is weird, because they both point to /. I'm not sure what the best default would be for most users: to only keep the former or only the latter. For me I'd say only keep "Home".

There's another discussion, but probably best left for subsequent PRs: would most users prefer it if we defaulted to not showing the Post Archives item when it refers to the 'post' post type?

@ntsekouras ntsekouras force-pushed the breadcrumbs/add-archive-link-if-enabled-in-posts branch from 3b0734f to 1ba0014 Compare November 19, 2025 09:39
@ntsekouras
Copy link
Contributor Author

Displaying both "Home" and "Post Archives" is weird, because they both point to /. I'm not sure what the best default would be for most users: to only keep the former or only the latter. For me I'd say only keep "Home".

I'd say the same, I'll create a follow up PR for this.

@ntsekouras ntsekouras enabled auto-merge (squash) November 19, 2025 09:44
@ntsekouras ntsekouras merged commit 2360184 into trunk Nov 19, 2025
33 of 34 checks passed
@ntsekouras ntsekouras deleted the breadcrumbs/add-archive-link-if-enabled-in-posts branch November 19, 2025 11:00
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 19, 2025
@tyxla
Copy link
Member

tyxla commented Nov 19, 2025

Displaying both "Home" and "Post Archives" is weird, because they both point to /. I'm not sure what the best default would be for most users: to only keep the former or only the latter. For me I'd say only keep "Home".

I'd say the same, I'll create a follow up PR for this.

Why do we have "Post Archives" for the post post type? AFAIK has_archive is false for the post post type. Maybe if someone tinkered with the register_post_type_args or the similar filters, we could check if the has_archive is true and determine whether to display that item that way (potentially with an extra URL check, ensuring it's not the same URL as home_url( '/' ))?

@ntsekouras
Copy link
Contributor Author

Why do we have "Post Archives" for the post post type?

Because we use get_post_type_archive_link and has extra logic for post and page.

After that special handling the has_archive is checked. So the only thing needed is to add the check with home_url in conjunction with show home attribute.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants