Skip to content

Allow filtering available templates for a specific post #83120

Open

Description

@gigitux

Problem

Plugins need a way to customize the templates available in the post editor for a specific post. A template’s relevance can depend on the post being edited, rather than only its post type.

Gutenberg already applies post-specific restrictions through hardcoded logic in useAllowSwitchingTemplates: template switching is disabled for the designated posts page and for the designated homepage when a front-page template exists.

However, plugins have no equivalent public extension point to filter the available templates for an individual post. For example, WooCommerce needs to restrict the template choices for its configured Shop page without affecting other pages. This is the current behavior:

CleanShot.2026-09-18.at.10.24.02.mp4

Classic themes already support filtering the available templates with theme_{$post_type}_templates. The filter receives the post being edited, allowing plugins and themes to adjust template choices for an individual post rather than applying the same list to every post of that type.

Proposal

Pass the edited post’s slug and post_type from the templates REST endpoint to the existing get_block_templates filter, allowing plugins and themes to customize template choices for a specific post.

The editor should use the returned list for template resolution, previews, and controls. It should keep the assigned template when it appears in the list; otherwise, it should use the first returned template. An empty list falls back to the template hierarchy. Returning a single template makes it the effective template and disables switching, without automatically changing the saved assignment.

I implemented a POC with #83083

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Templates APIRelated to API powering block template functionality in the Site Editor[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions