Hide the "Additional CSS Class" Field From Non-Administrators
Removes the Additional CSS class(es) field from the block Advanced panel for non-administrators, keeping authors to the styles you have designed.
Opens WPIDE on
Code
add_filter( 'block_type_metadata', function ( $metadata ) {
if ( current_user_can( 'manage_options' ) || empty( $metadata['name'] ) ) {
return $metadata;
}
$metadata['supports'] = isset( $metadata['supports'] ) ? (array) $metadata['supports'] : array();
$metadata['supports']['customClassName'] = false;
return $metadata;
} );
Notes
Classes already added to blocks are kept.
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.