Skip to content

Instantly share code, notes, and snippets.

@bob-moore
Created April 10, 2019 22:01
Show Gist options
  • Save bob-moore/92395ea6399d6765f5e944458a043f90 to your computer and use it in GitHub Desktop.
Save bob-moore/92395ea6399d6765f5e944458a043f90 to your computer and use it in GitHub Desktop.
<?php
function reorder_admin_menu( $menu_items ) {
// Our top level items
$top_level = array();
// Post Types
$post_types = array();
// Our bottom level items
$bottom_level = array();
// And our penalty box...known that we want last
$penalty_box = array();
// Loop over each item
foreach( $menu_items as $menu_item ) {
/**
* Known offenders that we want to stick as low as possible
*/
if( in_array( $menu_item, array( 'jetpack', 'genesis', 'woocommerce', 'edit.php?post_type=fl-builder-template' ) ) ) {
$penalty_box[] = $menu_item;
}
/**
* Our top level items
* Dashboard, and the first seperator
*/
if( in_array( $menu_item, array( 'index.php', 'separator1' ) ) ) {
$top_level[] = $menu_item;
}
/**
* Content related items
* anything that starts with edit.php and not already in the penalty box
* Nested pages plugin is whitelisted for this section
*/
else if( strripos( $menu_item , 'edit.php' ) !== false || $menu_item === 'nestedpages' ) {
$post_types[] = $menu_item;
}
/**
* Everything else
* Contains settings, users, appearence, etc.
*/
else {
$bottom_level[] = $menu_item;
}
}
// Mush it all together in a new order, and send it back
return array_merge( $top_level, $post_types, $bottom_level, $penalty_box );
}
add_filter( 'menu_order', 'reorder_admin_menu', 99 );
/**
* Add flag to allow custom menu order
*/
add_filter( 'custom_menu_order', '__return_true' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment