Home / Admin / Hide Admin Menu Items
Duplicate Snippet

Embed Snippet on Your Site

Hide Admin Menu Items

This snippet allows you to hide specific menu items from the admin for a certain user role. Please note that this doesn't prevent them from accessing those pages if they have the direct link and you should remove the role permissions if that's the intention.

<10
Code Preview
php
<?php
function wpcode_custom_remove_admin_menus(){
	// Replace "user_role" with the user role you want to target.
	if ( ! current_user_can( 'user_role') ) {
		return;
	}
	// Hide the comments page.
	remove_menu_page( 'edit-comments.php' );
	// Hide WooCommerce page.
	remove_menu_page( 'woocommerce' );
	// Hide the wpcode menu
	remove_menu_page( 'wpcode' );
}
add_action( 'admin_menu', 'wpcode_custom_remove_admin_menus', 150 );

Comments

Add a Comment