A snippet to hide the ACF 'Custom Fields' menu item from the wp-admin area.

If you’re using ACF-JSON to manage your field groups there’s typically no need to see the ACF Menu item called ‘Custom Fields’¬†on your staging or production sites.

It’s likely you’d need to keep the ACF ‘Custom Fields’ menu item visible for local development. You can use a variation of the snippet below to do exactly this. Just update the list of domains you wish to hide and you’ll be good to go!

<?php 
function awesome_acf_hide_acf_admin() {
		
    // get the current site url
    $site_url = get_bloginfo( 'url' );

    // an array of protected site urls  
    $protected_urls = array(
        'https://www.example.com',
        'http://staging.example.com'
    );

    // check if the current site url is in the protected urls array  
    if ( in_array( $site_url, $protected_urls ) ) {

        // hide the acf menu item 
        return false;
      
    } else {

        // show the acf menu item 
        return true;
      
    }
  
}

add_filter('acf/settings/show_admin', 'awesome_acf_hide_acf_admin');
?>					

Keep up to date with all things ACF!

Subscribe to our newsletter or follow @awesomeacf on Twitter!