WordPress 6.7 Block Hooks: Insert Blocks into Template Parts
WordPress block themes use template parts to organize shared areas of a site, such as headers and footers.
The upcoming WordPress 6.7 release expands block hooks so plugins can insert a hooked block as the first or last child of a Template Part block without editing the theme’s saved markup. Try this on a test installation of the 6.7 prerelease; see the WordPress developer note.
This gives site owners and developers a way to extend shared layouts while keeping the theme’s original content intact.
Understanding how block hooks work in template parts helps you know when they’re useful and what to expect.
How Block Hooks Work With Template Parts
When WordPress 6.7 finds a block hook in a template part, it can add the hooked block beside the block that triggered it. You define the relationship in the hooked block’s metadata, so WordPress knows which block to find and where to place the addition.
During the Block hook rendering lifecycle, WordPress processes the template part’s blocks, checks for matching hooks, and inserts the hooked block at the requested position. You don’t need to edit the template part’s saved markup for this automatic insertion.
The template part context resolution step matters because WordPress must identify the part being rendered and its surrounding context. That lets your hooked block appear in the right area, such as a header or footer.
Test the result in the site editor and on the front end, since rendering conditions can affect what you see. You can adjust the hook position when the placement doesn’t fit your layout.
Check Which Template Parts Support Block Hooks
Start by checking which template parts your theme supports, since block hooks won’t work everywhere. Confirm your theme’s compatibility, then inspect its template parts to find valid hook locations.
Supported Template Parts
Block Hooks apply in supported block contexts, including templates and template parts. The upcoming WordPress 6.7 release adds first-child and last-child insertion for the core/template-part block.
A template part’s area describes its role, such as a header or footer; it does not by itself restrict a metadata hook to that part. A hook on core/template-part can match multiple parts, so use the hooked_block_types filter and inspect the anchor block’s attributes and available context when a narrower condition is needed.
- A header can suit a navigation or announcement block.
- A footer may fit a related-links block.
- General or custom parts can also contain matching blocks; check their context before applying a condition.
Choose an anchor block and supported position that fit the content. Test all matching template parts rather than assuming the area alone limits insertion.
Theme Compatibility Checks
After inspecting the theme’s template parts, confirm that the target block is present and test the hook in the relevant context.
Start with Theme version auditing: check the theme’s style.css header and note its version. Compare that version with the WordPress release and the theme’s documentation, then test how the theme uses its template parts.
Next, open the site editor and check whether the theme provides the relevant template part.
If you maintain the theme, review its template markup and confirm that the expected anchor block is present. Test with a staging site before relying on the result in production.
For classic theme assessment, check whether the theme uses block-based template parts at all. A classic theme may not expose them, so Block Hooks mightn’t apply.
Don’t assume compatibility from appearance alone; verify the theme’s structure and documentation.
Inspecting Hook Locations
To see where a hooked block can appear, inspect the theme’s registered template parts and their hook locations. Check the theme files or Site Editor first, then confirm each part’s name and markup before choosing an insertion point.
This Inspecting Hook Context step helps you avoid placing a block in a part the theme doesn’t register or support.
- In
theme.json, review registered template parts, such asheaderorfooter. - Open each part’s HTML file and note its existing blocks and structure.
- Test the hook in the editor or on a staging site to confirm its position.
For Mapping Insertion Points, compare the target part with the page layout where you expect visitors to see the block. A header part may appear across many pages, while a template-specific part may appear only on one layout.
Check mobile and desktop views, too. If the location differs from your expectation, adjust the hook or select another registered part.
Register a Block Hook for a Header or Footer
If you want a block to appear in a theme’s header or footer, register it as a block hook and target the matching template part.
Define the hook in your block’s metadata so WordPress knows the anchor block and relative position. WordPress 6.7 is required for the first-child and last-child positions on template parts.
Register a header block hook
- Open your block’s
block.jsonfile. - Add a
blockHooksentry withcore/template-partas the anchor block type. This identifies a block type, not a particular header part. - Set its position to
firstChildorlastChild. To limit insertion to a particular part, use thehooked_block_typesfilter, inspect the anchor attributes and available context, and test the condition; metadata alone does not select a header area.
Configure a footer block hook
For a footer-only block, use an appropriate context-aware filter condition rather than assuming the same core/template-part metadata targets only the footer.
Check the anchor block’s template-part attributes and test your filter against the intended footer and other template parts.
Then activate your plugin and inspect the template in the Site Editor. This verifies WordPress recognizes the hook.
Control Hook Placement and Prevent Duplicates
Set placement rules to choose where your hooked block appears, such as before or after a specific block.
Use an appropriate filter condition if the hook should affect only a particular header or footer.
The upcoming 6.7 release respects a hooked block’s supports.multiple setting. With multiple set to false, insertion is limited within each context, but the same block can still appear in more than one context on a page.
Placement Rules
Placement rules let you choose where a hooked block appears and keep it from showing up more than once.
In WordPress 6.7, you can guide its position relative to a target block, so it fits the template part’s layout. Think about placement boundaries first: a notice might belong near the post title, while a related link may work better after the content. Then apply ordering rules to keep hooked blocks in a useful sequence.
- Choose before or after the target block to set a clear position.
- Use a template part that contains the target, such as a header or footer.
- Check the rendered page, since surrounding blocks affect how the placement looks.
For example, place a small prompt after a navigation block, not inside the menu. Test the change on pages that use the template part, and adjust the hook position if the layout feels crowded. Keep your placement choice tied to the block’s purpose.
Preventing Duplicate Blocks
To keep a hooked block from appearing more than once, control where WordPress inserts it and check the template parts that contain its target block.
A header or footer may appear on several pages, so one insertion can show up repeatedly across your site. That isn’t always a duplicate, but it can surprise you.
Check before adding
- Review the hook’s placement rule. Choose one suitable position, and avoid adding the same block at multiple positions unless you want it repeated.
- Use duplicate detection when building or testing your hooked block. Check the rendered page, not just the editor, because shared parts can make repeats less obvious.
- Apply conditional insertion only when you can define a clear condition, such as showing a block in one context. Keep the condition narrow, and test pages where it should appear and where it shouldn’t. Remove overlapping rules.
Template Part Targeting
Preventing repeats starts with choosing the right template part for a hooked block. Check the template part hierarchy before you add a hook, then target the smallest shared area that fits.
A condition targeting a particular header can affect pages that use it, while a condition for a post template can have a narrower scope. Check the context provided by the filter instead of assuming metadata alone selects one part.
- Shared header: Add a notice once if every page using that header needs it.
- Post template: Place a related-content block where readers expect it on posts.
- Unique area: Choose a page-specific part when other templates shouldn’t show the block.
Before saving, preview each template that uses the part. Confirm the block appears once in the intended location, and check that alternate templates don’t inherit it unexpectedly.
If they do, narrow the target or move the hook.
Test and Troubleshoot Block Hooks in the Site Editor
How can you tell whether a block hook works as intended? Open the Site Editor, choose the template part you targeted, and inspect the hooked block’s position and settings.
Then preview a page that uses it, since editor changes may not appear on every template.
Test and troubleshoot
- Verify editor changes. Save your edits, refresh the editor, and confirm the block remains in the expected location. Check the front end in a private browser window to rule out cached output.
- Diagnose hook conflicts. If the block is missing or misplaced, temporarily disable other hooked blocks or related custom code, then test again. Review the hook name, target block, and insertion position for spelling or value errors.
- Check your result. Test another page using the same template part. If the issue persists, review WordPress debug logs for relevant errors before changing code.
Check Theme Compatibility and Common Limitations
If a hooked block still looks wrong after you’ve checked its placement, confirm that the target block and relevant template-part context are present.
Some themes use custom structures, so a valid hook may not appear where you expect. Check these common limits before changing your code:
- Template versioning: Open the Site Editor and inspect the template part. Older theme files may lack the block area or markup your hook targets, so update the theme or choose a supported location.
- Navigation compatibility: Navigation blocks can behave differently across themes. Test your hooked block in the editor and on the front end, especially in mobile menus.
- Block support: A theme may restrict certain blocks or styles in a template part. Try a basic paragraph block first, then add the intended block.
If the theme doesn’t expose a suitable area, use another supported template part or ask the theme developer about compatibility.
Frequently Asked Questions
What Is the Minimum WordPress Version Required to Use Block Hooks?
You need WordPress 6.4 or later for block hooks support. WordPress introduced this feature in version 6.4, so you can’t use block hooks on earlier releases; update your installation to access it.
Can I Use Block Hooks in a Child Theme?
Yes, you can use block hooks in a child theme—but a small detail matters. Using child theme block.json, you can register hooked blocks; Overriding parent theme hooks requires matching the parent’s hook configuration carefully to achieve your intended placement.
Do Block Hooks Affect Website Performance?
Block hooks usually won’t noticeably slow your site. You may see slight Block Hook Render Overhead as WordPress inserts blocks, while Template Caching Effects can reduce repeated work. Test your pages, and optimize hooked blocks if performance drops.
Can I Insert a Block With Custom Attributes Using a Block Hook?
A hooked block can use its registered attribute defaults. For other values, use a supported PHP filter such as hooked_block to alter the inserted markup, and test the result in the editor and on the front end.
How Do Block Hooks Differ From Reusable Blocks?
Block hooks provide Automatic block placement through Theme integration, so you can inject blocks into templates based on rules. Reusable blocks let you save and manually insert shared content, which you can edit once for every instance.
- Block Hooks
- Template parts
- WordPress blocks
About the author
Vladimir Mrkela
Senior WordPress Developer
I’m a senior WordPress developer and co-founder of Pixel Industry. I’ve spent more than 12 years building websites, custom plugins, and integrations for all kinds of projects. I enjoy working on complex architecture, solving tricky problems, and sharing what I learn along the way.