Disable Custom Fields Editing on a Live Site

Overview

When delivering a website to a client, it may be beneficial to hide the ACF “Custom Fields” menu item. This prevents your client from changing or deleting fields and keeps the site running smoothly.

This doc details three methods for hiding the ACF menu:

  • Hiding the menu for all users on every site.
  • Hiding the menu for specific users on every site.
  • Hiding the menu on a live site while retaining functionality on the staging site.

This last option is likely the most common use case, as it allows you to continue editing fields when needed while ensuring that clients can’t make any unauthorized changes.

Hide for All Users

The ACF menu item can be hidden for all users by adding the following code to your functions.php file. Please note that __return_false is a WordPress function which simply returns false.

add_filter('acf/settings/show_admin', '__return_false');

Hide for Specific Users

The code above can be enhanced to only return false for specific users. The following code uses the WordPress function current_user_can() to return true or false depending on the current user’s capability. Please note that manage_options is a capability that only admins (and super admins) have by default.

add_filter('acf/settings/show_admin', 'my_acf_show_admin');

function my_acf_show_admin( $show ) {

    return current_user_can('manage_options');

}

Hide on Live Site Only

Adding the code below to your functions.php file hides the ACF menu on a live site, while retaining it on a staging or local development site.

if ( wp_get_wp_environment() === 'production' ) {

    // Only allow fields to be edited on development
    add_filter( 'acf/settings/show_admin', '__return_false' );

}