Hide the Custom Fields Box From Non-Administrators
Removes the raw "Custom Fields" box from the editor for everyone except administrators, so editors cannot accidentally change values that plugins and the theme depend on.
Opens WPIDE on
Code
add_action( 'add_meta_boxes', function () {
if ( current_user_can( 'manage_options' ) ) {
return;
}
foreach ( get_post_types( array( 'show_ui' => true ) ) as $post_type ) {
remove_meta_box( 'postcustom', $post_type, 'normal' );
}
}, 99 );
Notes
Fields shown in proper boxes by plugins such as ACF are not affected.
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.