by Matt Watson on WordPress.org
Enhance your site’s flexibility with Dynamic Template Parts, allowing you to swap headers, footers, and more on a post-by-post basis.

Use alternative Template Parts: Use the Full Site Editor to define your alternative template parts.
Transform the way you manage templates on your WordPress site with Dynamic Template Parts. This powerful plugin extends the Full Site Editor, letting you swap headers, footers, and other Template Parts dynamically based on the content you’re editing — say goodbye to managing multiple templates for every layout variation.
With Dynamic Template Parts, you gain the freedom to swap Template Parts directly within the block editor, whether it’s for posts, pages, or custom post types. The user-friendly interface allows you to preview changes in real-time, giving you complete control over the look and feel of each piece of content without needing custom code.
Key Features:
Get Started:
To implement an alternative Header Template Part using the Full Site Editor, please follow the example workflow below:
Unlock the power of dynamic templating and take control of your site’s design like never before!
Dynamic Template Parts provides filters to allow developers to customise its behaviour. Below are the available filters and how to use them.
The dynamic_template_parts_show_deselected_template_part filter lets you control whether a previously selected template part that is no longer available for selection should still be displayed. By default, the plugin keeps the part visible to avoid unintended changes, but you can override this to automatically remove unavailable template parts.
Example:
If you want to ensure that unavailable template parts are removed and replaced with the default template part, you can use the following code:
add_filter( 'dynamic_template_parts_show_deselected_template_part', function( $show_deselected, $template_parts, $selected_part ) {
// Always hide deselected template parts and fall back to the default.
return false;
}, 10, 3 );
Parameters:
$show_deselected (bool): Whether to show the deselected template part. Defaults to true.$template_parts (array): The list of available template parts.$selected_part (string): The currently selected template part.The dynamic_template_parts_user_can_switch filter lets you customise which users are allowed to switch template parts. By default, any user with the edit_posts capability can access this functionality, but you can restrict it to specific roles or capabilities.
Example:
If you want to restrict template part switching to administrators only, you can use the following code:
add_filter( 'dynamic_template_parts_user_can_switch', function( $can_switch ) {
// Allow only administrators to switch template parts.
return current_user_can( 'manage_options' );
} );
Parameters:
$can_switch (bool): Whether the current user has permission to switch template parts. Defaults to checking the edit_posts capability.See the Roadmap section for known issues.