When we build WordPress sites, we almost always re-arrange the menu items in the admin area. It lets us prioritize the content our partner is going to need to access, while removing content that may be unnecessary.
Usually, that means doing the following:
These changes make sense when the website isn’t a blog first and commenting isn’t allowed anywhere.
Making these tweaks is relatively easy, especially if you’re comfortable working with your site’s functions.php file.
There are two WordPress functions that make this magic happen.
This function creates a custom menu order to replace the normal menu order:
add_filter( 'custom_menu_order', 'dgtlnk_custom_menu_order', 10, 1 );
add_filter( 'menu_order', 'dgtlnk_custom_menu_order', 10, 1 );
function dgtlnk_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 function removes pages from the menu; in this example, the Comments link is removed.
add_action( 'admin_menu', 'dgtlnk_remove_menus' );
function dgtlnk_remove_menus(){
remove_menu_page( 'edit-comments.php' );
}
Using these functions to re-arrange the menu items for your project is easy enough.
Simply take the menu items you want, grab their URL slug (everything past the /wp-admin/), and re-order as in the first function. Add separators as necessary.
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 above), everything else will display in its normal order below the customizations you’ve made.
To remove links from the menu, simply insert the page’s slug (URL) in the “remove_menu_page” function. To remove multiple pages, call the function multiple times for each page you want to remove.