Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to hide an admin menu in WordPress based on a user role
/* check if user is administrator - only show downloads menu if is admin */
add_action( 'admin_init', 'nh_remove_menu_pages' );
function nh_remove_menu_pages() {
global $user_ID;
//if the user is NOT an administrator remove the menu for downloads
if ( !current_user_can( 'administrator' ) ) { //change role or capability here
remove_menu_page( 'edit.php?post_type=wpdmpro' ); //change menu item here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment