07788 994423 ยท [email protected]

Hide the ACF menu and show for a specific user only

Advanced Custom Fields (ACF) is a popular plugin for WordPress that provides additional customization options for website administrators. However, when delivering a website to a client, it may be necessary to limit their access to the ACF menu item in order to prevent them from accidentally making changes to the website that could cause problems.

This can be achieved by adding a code snippet to the website’s functions.php file. The code uses the ACF filter ‘acf/settings/show_admin’ to determine whether or not the ACF menu item should be displayed.

The code defines a function ‘my_acf_show_admin’ that takes a single argument, $show. The function checks the current user ID using the get_current_user_id() function, and if the ID is equal to “1” (which is the ID for the first user in the WordPress system), it returns true, which means the ACF menu item will be displayed.

For all other users, the function returns false, which means the ACF menu item will be hidden. This will allow the website administrator (user ID 1) to access the ACF menu but prevent other users from making changes to the website fields.

By using this code, you can ensure that the website runs smoothly and that the client is not able to make changes that could cause problems.

Place code in your functions.php


add_filter('acf/settings/show_admin', 'my_acf_show_admin');
function my_acf_show_admin( $show ) { 
if ( get_current_user_id() == "1" ){
return true; // show it
   }
else {
return false; // hide it
   }
}