Skip to content

Instantly share code, notes, and snippets.

@ethanpil
Created December 26, 2022 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanpil/e3c0832004dbedf9229d6730560fcf6c to your computer and use it in GitHub Desktop.
Save ethanpil/e3c0832004dbedf9229d6730560fcf6c to your computer and use it in GitHub Desktop.
Re-Order and Hide Wordpress Admin Menu Items
<?php
/* How to Rearrange/Hide WordPress Admin Menu Links
Source: https://www.digital.ink/blog/wordpress-rearrange-admin-menu/
1) Find the URL slug of relevant menu items (everything past the /wp-admin/)
2) Re-order as in the first function.
3) Add separators as necessary.
NOTE: If you don’t add an item to your custom menu order, and don’t remove it completely,
it will fall in line below your custom order. So if you only want to re-order the first few
menu items (as seen below), everything else will display in its normal order below the
customizations you’ve made.
To remove links from the menu:
1) Insert the page’s slug (URL) in the "remove_menu_page" function.
NOTE: To remove multiple pages, call the function multiple times, once
for each page you want to remove.
*/
//This filter+function creates a custom menu order to replace the normal menu order:
add_filter( 'custom_menu_order', 'mysite_custom_menu_order', 10, 1 );
add_filter( 'menu_order', 'mysite_custom_menu_order', 10, 1 );
function mysite_custom_menu_order( $menu_ord ) {
if ( !$menu_ord ) return true;
return array(
'index.php', // Dashboard
'separator1', // First separator
'edit.php?post_type=page', // Pages
'edit.php', // Posts
);
}
//This action+function removes pages from the menu; in this example, the Comments link is removed
add_action( 'admin_menu', 'mysite_remove_menus' );
function mysite_remove_menus(){
remove_menu_page( 'edit-comments.php' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment