Reputation: 655
I have this code that removes pages from users that are not admin on a site I developing.
function remove_menu_items() {
if (!current_user_can('manage_options')){
remove_menu_page( 'index.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'edit.php' );
remove_menu_page( 'edit.php?post_type=page' );
remove_menu_page( 'edit.php?post_type=hp_slides' );
remove_menu_page( 'post-new.php?post_type=foodswaps' );
}
}
add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
However the bottom remove item doesn't work, the post type is correct but the sub menu item still remains. Can any one see what I have done wrong?
Upvotes: 4
Views: 2571
Reputation: 103
I had this problem a couple weeks ago!
So you are trying to remove a submenu item, therefore need to use something like this:
function remove_menu_items() {
if ( ! current_user_can( 'manage_options' ) ) {
// remove new post button from the food swaps custom post type if not admin
$page = remove_submenu_page( 'edit.php?post_type=foodswaps', 'post-new.php?post_type=foodswaps' );
}
}
add_action( 'admin_menu', 'remove_menu_items' );
Upvotes: 6