Wordpress Snippets

Remove Submenu Items From The WordPress Admin

In previous article we show you how to clean WordPress admin dashboard by removing WordPress dashboard widgets. In this article, we will discuss how we can remove submenu items from the WordPress admin.

Sometimes you might need to remove posts, pages, plugins or other submenus items from the WordPress dashboard. For example, if you are working on a project for a client and let’s say you want to hide theme editor so they cannot change any theme files or may be settings menu to restrict them change any settings. FOr whatever reason you want to remove submenu items, WordPress makes this task extremely easy. WordPress 3.1 introduced remove_submenu_page() function, which makes it very easy for us to remove submenu items.

It’s important to note that this function only removes submenu items from the WordPress administration menu. It does not block access to menu pages via direct URL. It’s great for hiding things, but it should not be used as a way to secure specific admin screens. For that, you’ll need to work with the capability system.

To remove submenu items from WordPress admin dashboard, simply paste this code snippet to the functions.php file in your WordPress theme. Don’t forget to delete or comment out whichever options you don’t wish to use.

// remove submenu items from the wordpress admin
function wcs_remove_submenus() {
    global $submenu;

    // dashboard menu
    unset( $submenu['index.php'][10] ); // removes updates

    // posts menu
    unset( $submenu['edit.php'][5] ); // removes list of posts
    unset( $submenu['edit.php'][10] ); // removes add new post
    unset( $submenu['edit.php'][15] ); // remove categories
    unset( $submenu['edit.php'][16] ); // removes tags

    // media menu
    unset( $submenu['upload.php'][5] ); // removes view media library
    unset( $submenu['upload.php'][10] ); // removes add to media library

    // links menu
    unset( $submenu['link-manager.php'][5] ); // removes link manager
    unset( $submenu['link-manager.php'][10] ); // removes add new link
    unset( $submenu['link-manager.php'][15] ); // removes link categories

    // pages menu
    unset( $submenu['edit.php?post_type=page'][5] ); // removes list of pages
    unset( $submenu['edit.php?post_type=page'][10] ); // removes add new page

    // appearance menu
    unset( $submenu['themes.php'][5] ); // removes themes
    unset( $submenu['themes.php'][7] ); // removes widgets
    unset( $submenu['themes.php'][15] ); // removes theme installer

    // plugins menu
    unset( $submenu['plugins.php'][5] ); // removes plugin manager
    unset( $submenu['plugins.php'][10] ); // removes add new plugins
    unset( $submenu['plugins.php'][15] ); // removes plugin editor

    // users menu
    unset( $submenu['users.php'][5] ); // removes list of users
    unset( $submenu['users.php'][10] ); // removes add new user
    unset( $submenu['users.php'][15] ); // removes edit your profile

    // tools menu
    unset( $submenu['tools.php'][5] ); // removes tools area
    unset( $submenu['tools.php'][10] ); // removes import
    unset( $submenu['tools.php'][15] ); // removes export
    unset( $submenu['tools.php'][20] ); // removes upgrade plugins and core files

    // settings menu
    unset( $submenu['options-general.php'][10] ); // removes general options
    unset( $submenu['options-general.php'][15] ); // removes writing
    unset( $submenu['options-general.php'][20] ); // removes reading
    unset( $submenu['options-general.php'][25] ); // removes discussion
    unset( $submenu['options-general.php'][30] ); // removes media
    unset( $submenu['options-general.php'][35] ); // removes privacy
    unset( $submenu['options-general.php'][40] ); // removes permalinks
    unset( $submenu['options-general.php'][45] ); // removes misc
}
add_action( 'admin_menu', 'wcs_remove_submenus' );

Hire Us. Or just say Hi!
Need a job? Apply to get one.