Skip to content

Archive template is listed in singular post's template select #79696

Open

Description

@benoitchantre

Description

When you register a public custom post type and then add an archive template file (archive-{post-type}.html), there's a template picker displayed when the post type supports page-attributes.

When you delete that template file and use the site editor to add the template, there's no template picker displayed.

Step-by-step reproduction instructions

  1. Install Custom Post Type UI Plugin
  2. Import the following Post Type
  3. Add an archive-event.html template file
  4. See that the page attributes show an unneeded template picker
  5. Delete that template file and use the site editor to add an archive template for the Events
  6. See that the template picker isn't displayed
Image
{"event":{"name":"event","label":"Events","singular_label":"Event","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","delete_with_user":"false","show_in_rest":"true","rest_base":"","rest_controller_class":"","rest_namespace":"","has_archive":"true","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","can_export":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"false","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":null,"register_meta_box_cb":null,"supports":["title","page-attributes"],"taxonomies":[],"labels":{"menu_name":"","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","filter_by_date":"","items_list_navigation":"","items_list":"","attributes":"","name_admin_bar":"","item_published":"","item_published_privately":"","item_reverted_to_draft":"","item_trashed":"","item_scheduled":"","item_updated":"","template_name":""},"custom_supports":"","enter_title_here":""}}

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. Swanand01 commented on Jul 13, 2026

    @Swanand01
    Contributor

    The cause is in get_block_templates(): when a theme-provided template file has no explicit postTypes metadata, WordPress falls back to checking whether its slug is one of the "reserved" hierarchy template names (archive, single, taxonomy, etc.) via get_default_block_template_types(). If it's not in that list, it's treated as a generic custom template that's available for every post type.

    The problem is that list only contains the generic base names, it never accounts for the post-type/taxonomy-specific versions like archive-event or single-event. So archive-event.html isn't recognized as "reserved," falls through to the generic bucket, and ends up offered as a selectable Template for singular event posts too, even though it's clearly meant only for the archive.

    Interestingly, core already has the right pattern for this. It dynamically adds entries to that same list for post formats (e.g. taxonomy-post_format-post-format-video) via the default_template_types filter. It just was never extended to cover custom post types/taxonomies.

    The fix would hook the same default_template_types filter to dynamically register archive-{post_type}, single-{post_type}, and taxonomy-{taxonomy} entries for all registered post types/taxonomies.

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

Metadata

Metadata

Assignees

Labels

[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions