Disable Block Locking in WordPress

Last updated:

Learn how to disable the block locking feature in WordPress. You can disable it by specifying the post type (post, page, etc.), user permissions or specific users.

What is locking the block?

Locking blocks is a feature added since WordPress 6.0 that allows you to move blocks, delete blocks, or disable both.

Locking Blocks

For other new features added in WordPress 6.0, please see the following articles.

Disable Block Locking

If you do not use block locking, you can disable it with a filter hook.

Disable Post Only

To disable post-only block locking, add the following code to the functions.php of the theme you are enabling.

add_filter(
    'block_editor_settings_all',
    function( $settings, $context ) {
        if ( $context->post && $context->post->post_type === 'post' ) {
            $settings['canLockBlocks'] = false;
        }
        return $settings;
    },
    10,
    2
);

Disable Pages Only

To disable the lock feature for page only blocks, add the following code to the functions.php of the enabled theme.

add_filter(
    'block_editor_settings_all',
    function( $settings, $context ) {
        if ( $context->post && $context->post->post_type === 'page' ) {
            $settings['canLockBlocks'] = false;
        }
        return $settings;
    },
    10,
    2
);

Allow for the Editor role and above

To disable the lock feature of the less-than-editor (subscriber, contributor, and author) only block, add the following code to the functions.php of the theme you are enabling.

add_filter(
    'block_editor_settings_all',
    function( $settings, $context ) {
        $settings['canLockBlocks'] = current_user_can( 'delete_others_posts' );
        return $settings;
    },
    10,
    2
);

Only enable for specific user(s)

To disable the lock feature of the block for specific users only, add the following code to the functions.php of the enabled theme.

Specify in user@example.com the email address of the user for whom you wish to disable the lock feature of the block.

add_filter(
    'block_editor_settings_all',
    function( $settings, $context ) {
        $user = wp_get_current_user();
        if ( in_array( $user->user_email, [ 'user@example.com' ], true ) ) {
            $settings['canLockBlocks'] = false;
        }
        return $settings;
    },
    10,
    2
);
go to top