Tutorials

How to lock blocks in WordPress

If you build WordPress sites for other people, you’ve probably handed one over and come back to find a column deleted or a header dragged to the bottom of the page, usually following a frenzied phone call from the client. Block locking is WordPress’s answer. You can stop a block from being moved or removed, or set up a section so that editors can change its text and images but not its layout.

There are two ways to do it: in the editor, which works on any site, and in code, for theme and pattern developers. I’ll go through both, and the limits worth knowing about before you rely on it.

Lock a block in the editor

  1. Select the block you want to lock.
  2. Click the three dots in the block toolbar and choose “Lock”.
  3. Choose what to lock: “Lock movement” stops the block from being dragged or moved up and down, and “Lock removal” stops it from being deleted. “Lock all” turns on both.
  4. Click “Apply”.

A locked block shows a padlock in its toolbar and in List View. To unlock it, click the padlock (“Unlock”) and untick the options.

On container blocks like Group, Columns and Cover, the dialog also has an “Apply to all blocks inside” toggle. That’s the quickest way to lock down a whole section: lock the group around it and apply the lock to everything inside.

Let editors change only the content

Locking movement and removal keeps blocks in place, but editors can still change their colors, spacing and settings. If you want them to change only the words and images, use content-only editing.

Since WordPress 7.0, it’s the default for patterns. When you insert an unsynced pattern, you can edit its text, images and links straight away, but the blocks that hold the layout, like groups, columns and spacers, are hidden, and so are the design settings. To change the layout, click “Edit pattern” in the toolbar, or double-click the pattern, and you get full editing for that pattern only.

That makes patterns the easiest way to hand a client a section they can update but not break. Build the section, save it as a pattern (“Create pattern” in the three dots), and have them insert the pattern instead of building from scratch. Synced patterns work the same way, except that an edit to the pattern changes it everywhere it’s used, so “Edit original” opens it in its own editor.

For a section that isn’t a pattern, content-only editing on a Group, Columns or Cover block can only be turned on in code. There’s no button for it in the editor yet.

Lock blocks in a theme or pattern

If you make themes or patterns, you can ship blocks already locked. A lock is stored as a lock attribute in the block markup, so the easiest way to get it right is to lock the blocks in the editor, open the Code editor, and copy the markup into your pattern or template file:

<!-- wp:group {"lock":{"move":true,"remove":true}} -->
<div class="wp-block-group">
<!-- wp:heading -->
<h2 class="wp-block-heading">Opening hours</h2>
<!-- /wp:heading -->
</div>
<!-- /wp:group -->

To lock everything inside a container, add templateLock to the Group, Columns or Cover block:

  • "templateLock":"all" stops blocks inside from being added, moved or removed.
  • "templateLock":"insert" stops blocks from being added or removed, but they can still be moved.
  • "templateLock":"contentOnly" hides the layout blocks and design settings, and leaves only the text, images and links editable. This is the one to use for a section a client should only fill in.
<!-- wp:group {"templateLock":"contentOnly"} -->

A lock on a single block overrides the templateLock of the container around it, so you can lock a whole section and still let one block inside be removed.

If you’d rather patterns didn’t open in content-only mode, you can turn the 7.0 default off:

/**
* Opens unsynced patterns with full editing instead of content-only mode.
*
* @param array $settings The block editor settings.
* @return array The filtered settings.
*/
function my_disable_content_only_patterns( $settings ) {
$settings['disableContentOnlyForUnsyncedPatterns'] = true;
return $settings;
}
add_filter( 'block_editor_settings_all', 'my_disable_content_only_patterns' );

Stop editors from unlocking

A lock is a guard against mistakes, not a permission. Anyone who can lock a block can also unlock it, so if editors can use the Lock dialog, they can undo your locks. To keep locking for administrators only, add this to your theme’s functions.php or a small plugin:

/**
* Only lets users who can edit theme options lock and unlock blocks.
*
* @param array $settings The block editor settings.
* @return array The filtered settings.
*/
function my_restrict_block_locking( $settings ) {
$settings['canLockBlocks'] = current_user_can( 'edit_theme_options' );
return $settings;
}
add_filter( 'block_editor_settings_all', 'my_restrict_block_locking' );

Even then, it isn’t airtight: someone who opens the Code editor can delete the lock attribute by hand. For most client sites, that’s fine. The point is to stop a stray drag or delete, not to stop someone who’s determined.

Locking also doesn’t cover styles. To stop editors from picking their own colors, gradients and font sizes, see how to lock down colors and fonts in a block theme. Together, the two let you hand over a site where editors can change what it says, but not how it looks.

Published December 1, 2026