Remove Customize Background and Header from Appearance admin menu without CSS or JS

As overcomplicated as it sounds, I always find the best way to handle admin menu modifications is to overlook the given wordpress remove_ functions and go straight to the $menu and $submenu globals. In the case you’ve specified here, you’d want to change your code to:

add_action('admin_menu', 'remove_unnecessary_wordpress_menus', 999);

function remove_unnecessary_wordpress_menus(){
    global $submenu;
    unset($submenu['themes.php'][20]);
    unset($submenu['themes.php'][22]);
}

The indices of the pages in the themes.php array seem strange, but what isn’t when you try to hack WP?! A good reference for using these globals can be found here.

EDIT: Just a thought, given the varying amounts of plugins etc. which could (potentially, but not definitely) change the index of a given menu/submenu item in the array, it’d be a good idea to check the numbers required if the snippet I’ve provided doesn’t work. You can do that by modifying the code slightly to this:

add_action('admin_menu', 'remove_unnecessary_wordpress_menus', 999);

function remove_unnecessary_wordpress_menus(){
    global $submenu;
    //Left margin is to account for the admin sidebar menu
    echo '<pre style="margin-left:11em">';
    print_r($submenu);
    echo '</pre>';
}

This will ‘pretty’ print the $submenu array, from which you can find the exact numbers you need.

EDIT: Since I don’t have the rep to comment on this community yet, it’s worth pointing out that @Fredrik did a good job of generalisation. +1.

Leave a Comment