wordpresswordpress-themingcustom-wordpress-pageswordpress-thesis-theme

How to hide advanced custom fields(ACF) in the WP-admin UI?


Check the screenshot below; all I want to do is to hide certain ACF fields for custom users in the wordpress backend.

enter image description here


Solution

  • 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".