How to hide advanced custom fields(ACF) in the WP-admin UI?
As of ACF 5.0.0 there is an easier way to do this without having to output CSS. If you use the acf/prepare_field
hook and return false
the field will not render.
<?phpfunction so37111468_hide_field( $field ) { // hide the field if the current user is not able to save options within the admin if ( ! current_user_can( 'manage_options' ) ) { return false; } return $field;}add_filter( 'acf/prepare_field/key=MYFIELDKEY', 'so37111468_hide_field' );?>
The documentation for that filter can be found here: https://www.advancedcustomfields.com/resources/acf-prepare_field/
If you mean to hide it with CSS, then you should insert custom CSS to admin footer area.For example, you can add such kind of code to your theme's functions.php file:
add_action('admin_footer', 'my_admin_hide_cf');function my_admin_hide_cf() { $u=wp_get_current_user(); $user_roles = $u->roles; if ($user_roles[0]=='CUSTOM_USER_ROLE_NAME'){ echo ' <style> #acf-FIELD_SLUG_HERE {display:none} </style>'; }}
And of course you should replace FIELD_SLUG_HERE and CUSTOM_USER_ROLE_NAME values with correct ones.F.e. #acf-FIELD_SLUG_HERE can be #acf-url, CUSTOM_USER_ROLE_NAME can be "contributor".