Stop Non-Administrators Changing Content Widths
Hides the content width and wide width fields in the layout settings of Group and similar blocks for everyone except administrators, so page widths stay consistent.
Opens WPIDE on
Code
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
if ( current_user_can( 'manage_options' ) ) {
return $theme_json;
}
return $theme_json->update_with( array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'layout' => array( 'allowCustomContentAndWideSize' => false ),
),
) );
} );
Notes
Needs WordPress 6.6+; older versions ignore the setting.
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.