How to hide (remove) WordPress menus in the admin area?

  

2
Topic starter

For a WordPress project I would like to hide (remove) a particular menu (or menus in the future) in the WP dashboard area (the admin area);

For example: Posts menu;

How can I do it?

I would prefer to use some PHP code as a function as I have child theme and can modilfy the functions.php file for it.

Thanks

P.s. Down below is a screenshot of the wordpress menu I want to hide:

how to hide wordpress menu in functions code

1 Answer
1

In your child's WordPress theme in the functions.php file add the following code:

/* Remove menus from the WordPress dashboard*/
function wpdocs_remove_menus() {
    remove_menu_page('index.php'); //Dashboard
    remove_menu_page('edit.php'); //Posts
    remove_menu_page('upload.php'); //Media
    remove_menu_page('edit.php?post_type=page'); //Pages
    remove_menu_page('edit-comments.php'); //Comments
    remove_menu_page('themes.php'); //Appearance
    remove_menu_page('plugins.php'); //Plugins
    remove_menu_page('users.php'); //Users
    remove_menu_page('tools.php'); //Tools
    remove_menu_page('options-general.php'); //Settings
    remove_menu_page('edit.php?post_type=project'); //Projects
}
 
add_action('admin_menu', 'wpdocs_remove_menus');

I've used the admin_menu WordPress hook (line #16);

For your case you can see the code on line #4 - for the Posts menu.

You can alsoread and see this link


For menus that are NOT related to the WordPress core (Pages, Posts, etc.) you can also use the admin_init (on line 8 below) hook;

In that case you must type the folder or the file of the plugin or the theme;

See the screenshot of what I mean (see line 4 for the Yoast WP plugin):

hide wordpress plugin or menu or theme

Here I am hiding:

  • Divi theme menu
  • WP Yoast SEO menu
  • Activity Log plugin

Here is the example (see the comments in the code below):

/* Hide plugin/theme/menu in the WordPress dashboard area */
function wpdocs_remove_menusTwo() {
    remove_menu_page('et_divi_options'); //Divi WP Theme
    remove_menu_page('wpseo_dashboard'); //Yoast SEO WP Plugin
    remove_menu_page('activity_log_page'); //Activity Log WP Plugin
}
 
add_action('admin_init', 'wpdocs_remove_menusTwo');

BTW, if you want a particular user (in my case administrator with id=1) NOT TO BE ABLE to see a menu (generated by a plugin), see the code below (see line #3):

/* Hide plugin/theme/menu in the WordPress dashboard area */
function wpdocs_remove_menusTwo() {
    if (get_current_user_id() == 1) {
        remove_menu_page('activity_log_page'); //Activity Log WP Plugin
    }
}
 
add_action('admin_init', 'wpdocs_remove_menusTwo');
Share: