
If you have ever handed a freshly built WordPress site to a client’s marketing team, you already know how fast a clean layout can unravel. Someone tries to fix a typo in a two-column hero section, accidentally hits Backspace on the Buttons block instead of the text, or drags a column out of its parent Group—and suddenly the homepage looks broken on mobile.
Block locking (introduced in WordPress 6.0/6.1) exists specifically to stop those accidental structural edits without forcing editors back into rigid custom fields for every paragraph. The trick is using the narrowest lock that solves the problem. Lock too much and writers will ping you on WhatsApp every time they need to swap a photo; lock nothing and fragile layouts will drift within a month.
Guardrails, not security boundaries
The Block Locking API controls three main things at the block level: whether a block can be moved (move), whether it can be deleted (remove), and—for certain blocks like Navigation or Synced Patterns—whether its inner structure can be edited. At the container level, templateLock can also restrict inserting or reordering child blocks.
One detail catches a lot of developers off guard: by default, any user who can edit posts can also click “Unlock” in the block toolbar. Out of the box, block locking is a UI seatbelt against clumsy clicks, not an access-control boundary. If you want locking to actually hold for Author or Editor roles, you have to pair the block attributes with a capability filter.
Choosing the smallest lock that works
Start from the mistake you are trying to prevent:
- Accidental deletion of a CTA or legal disclaimer: lock
removeonly, or bothmoveandremoveon that specific block. - Columns or pricing cards getting dragged out of order: lock
moveandremoveon the parentColumnsorGroup, while leaving the innerParagraphandHeadingblocks unlocked for normal writing. - A rigid landing-page pattern where writers should only swap text and images: set
"templateLock":"contentOnly"on the outerwp:grouporwp:cover.
Here is what contentOnly looks like in pattern or template markup:
<!-- wp:group {"templateLock":"contentOnly","layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:heading {"level":2} -->
<h2>Monthly Maintenance Plan</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Includes off-site backups, core updates, and uptime checks.</p>
<!-- /wp:paragraph -->
<!-- wp:buttons -->
<div class="wp-block-buttons">
<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="/contact/">Request a quote</a></div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
</div>
<!-- /wp:group -->
With templateLock: "contentOnly", WordPress hides the structural child wrappers in List View and removes typography, spacing, and colour controls from the sidebar for that section. An editor clicks the heading, types the new text, updates the button link, and moves on—zero risk of them changing the padding or deleting the wrapper.
For a single critical block inside an otherwise flexible section, block-level locking is simpler:
<!-- wp:paragraph {"lock":{"move":true,"remove":true}} -->
<p>Prices are quoted in MYR and exclude SST unless stated otherwise.</p>
<!-- /wp:paragraph -->
Restricting who is allowed to unlock blocks
If your editors should not be able to override locks, you can control the canLockBlocks setting via block_editor_settings_all. I usually tie this to edit_theme_options (which Administrators have and Editors do not) inside a small site-specific plugin so it survives theme switches:
add_filter( 'block_editor_settings_all', function ( $settings, $context ) {
if ( ! current_user_can( 'edit_theme_options' ) ) {
$settings['canLockBlocks'] = false;
}
return $settings;
}, 10, 2 );
Test this with an actual non-admin user account before shipping. Also keep in mind two caveats:
- If an editor has access to the Code Editor (
Ctrl+Shift+Alt+M/Cmd+Shift+Option+M), they can still see and strip"lock":{"move":true,"remove":true}directly from the HTML comment markup. If strict governance matters, restrictcanLockBlocksand consider disabling the Code Editor for non-admins or using server-rendered dynamic blocks for truly sensitive components. - Check whether your
block_editor_settings_alllogic affects the Site Editor or Custom Post Types differently—sometimes a marketing lead should be able to unlock blocks in alanding_pageCPT while staying locked out of global templates.
Where block locking backfires
Locking is the wrong tool when a layout is simply too complicated for the people using it. If editors constantly need to add a fourth feature card to a three-card grid, locking the grid does not solve their problem—it just creates support tickets. Either build a clean pattern they can duplicate, or move that structured data into a custom post type or ACF/meta fields.
Locking also adds friction during a redesign. Six months later, when you update the theme’s spacing tokens or swap a Columns block for a CSS Grid Group, any existing pages that stamped a locked pattern into post_content will still carry the old markup. Document which templates and patterns carry templateLock so future-you (or the next developer) knows where to look.
For related guides on keeping WordPress maintainable for teams, see:
- How to Evaluate a WordPress Plugin Before Installing It
- WordPress Template Parts: Reuse Site Structure Without Repeating Yourself
- WordPress Multisite Architecture: When to Use a Network and What to Check Before Enabling It
Treat block locking like a guardrail on a mountain road: put it on the sharp corners where a slip breaks the page, leave the straightaways open so writers can work fast, and verify with a real Editor login before calling the handoff complete.