How to Remove and Create Hidden WordPress Admin Pages

WordPress provides add_menu_page() and add_submenu_page() for creating top-level menu and sub menu admin pages. Settings pages created with these functions usually appear in the admin menu.

In this tutorial, we will learn how to remove admin pages / items from the admin menu and still be able to them directly via their page URL.

Removing Top Level Menu Pages

To remove top-level pages item in amin menu, use remove_menu_page() as follows, where the function parameter is the slug of the settings page.


function remove_menus(){
  remove_menu_page( 'jetpack' );          //Jetpack
  remove_menu_page( 'themes.php' );       //Appearance
  remove_menu_page( 'plugins.php' );      //Plugins
  remove_menu_page( 'users.php' );        //Users
  
}
add_action( 'admin_menu', 'remove_menus' );

The code above removes themes, plugins, users and Jetpack admin menu items.

Removing Submenu Pages

The function remove_submenu_page() is provided by WordPress for removing sub-menu pages from the admin menu.

To remove a submenu page with slug ‘pp-extra’ attached to a top-level menu with slug ‘pp-config’, see the code below.


add_action( 'admin_menu', 'remove_sub_menu_page', 999 );
function remove_sub_menu_page() {
  $page = remove_submenu_page( 'pp-config', 'pp-extra' );
}

To remove the widget submenu page:


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

function adjust_the_wp_menu() {
  remove_submenu_page( 'themes.php', 'widgets.php' );
}

Notes:
* A higher priority of 999 was used to ensure the adjust_the_wp_menu function which contain remove_submenu_page() run last.

* Removing submenu pages using the remove_submenu_page() prevent users from accessing the screen for the removed submenu directly. This lead us to the final section of this article on creating hidden admin pages that won’t be displayed or shown in admin menu.

Creating Hidden Admin Pages

To create a hidden submenu page, set the $parent_slug parameter of add_submenu_page() to options.php like so.


function hidded_submenu_page() {
	add_submenu_page(
		'options.php',
		__( 'Revision', 'profilepress' ),
		__( 'Revision', 'profilepress' ),
		'manage_options',
		'pp-revision',
		'callback_func'
	);

}

add_action( 'admin_menu', 'hidded_submenu_page' );

The code above creates a hidden settings page titled Revision.

To create a hidden top-level admin page; firstly, create the page using add_menu_page() and then remove the page from the admin menu with remove_menu_page().

It is worth noting that pages removed by remove_menu_page() can be access directly via the page URL unlike remove_submenu_page().

Using jQuery

You can also remove any admin page from WordPress admin menu by traversing the DOM and removing the menu element.

For example, the code below will remove a submenu page with menu title Revision


<?php
function remove_revision_menu() {
	?>
	<script type="text/javascript">
		(function ($) {
			$(document).ready(function () {
				$('div#adminmenuwrap li a').each(function (index) {
					if ($(this).text() == 'Revision') $(this).remove();
				});
			});
		})(jQuery);
	</script>
<?php }


add_action( 'admin_footer', 'remove_revision_menu' );

And this will remove the “Users” top level menu page.


<?php
function remove_user_menu() {
	?>
	<script type="text/javascript">
		(function ($) {
			$(document).ready(function () {
				$('div#adminmenuwrap li a').each(function (index) {
					if ($(this).text() == 'Users') $(this).parents('li').remove();
				});
			});
		})(jQuery);
	</script>
<?php }

add_action( 'admin_footer', 'remove_user_menu' );
Resources

* WordPress Cheat Sheet
* Learn WordPress

Don’t miss out!
Subscribe to My Newsletter
Invalid email address