Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Wendersonandes/18972346f41a1fcd081ff8be7b03ec19 to your computer and use it in GitHub Desktop.
Save Wendersonandes/18972346f41a1fcd081ff8be7b03ec19 to your computer and use it in GitHub Desktop.
Reorder Wordpress Admin Menu Items
/**
* Activates the 'menu_order' filter and then hooks into 'menu_order'
*/
add_filter('custom_menu_order', function() { return true; });
add_filter('menu_order', 'artvsm_new_admin_menu_order');
/**
* Filters WordPress' default menu order
*/
function artvsm_new_admin_menu_order( $menu_order ) {
// define your new desired menu positions here
// for example, move 'upload.php' to position #9 and built-in pages to position #1
$new_positions = array(
'upload.php' => 1,
'edit.php?post_type=page' => 2,
'edit.php' => 3
);
// helper function to move an element inside an array
function move_element(&$array, $a, $b) {
$out = array_splice($array, $a, 1);
array_splice($array, $b, 0, $out);
}
// traverse through the new positions and move
// the items if found in the original menu_positions
foreach( $new_positions as $value => $new_index ) {
if( $current_index = array_search( $value, $menu_order ) ) {
move_element($menu_order, $current_index, $new_index);
}
}
return $menu_order;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment