Content-Only Editing of Pages for Non-Administrators
Locks the layout of pages in the block editor for everyone except administrators, so editors can change text and images but cannot move, delete or restyle blocks and break the design.
Opens WPIDE on
Code
// Post types whose layout is locked.
$wpide_content_only_types = array( 'page' );
add_filter( 'block_editor_settings_all', function ( $settings, $context ) use ( $wpide_content_only_types ) {
if ( current_user_can( 'manage_options' ) || empty( $context->post ) || ! in_array( $context->post->post_type, $wpide_content_only_types, true ) ) {
return $settings;
}
$settings['templateLock'] = 'contentOnly';
return $settings;
}, 10, 2 );
Notes
Applies to the post types in $wpide_content_only_types; administrators edit normally.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.