Skip to content

Instantly share code, notes, and snippets.

@mindctrl
Created January 17, 2025 17:10
Show Gist options
  • Save mindctrl/1fc45d251676fa0191cbe1df5373ea25 to your computer and use it in GitHub Desktop.
Save mindctrl/1fc45d251676fa0191cbe1df5373ea25 to your computer and use it in GitHub Desktop.
Move all non-core WordPress admin menu items to the bottom of the sidebar
<?php
add_action( 'admin_menu', 'jp_reorder_admin_menu', 999 );
/**
* Reorder wp-admin sidebar menus
*/
function jp_reorder_admin_menu() {
global $menu;
if ( empty( $menu ) ) {
return;
}
// Core menu items and their default positions
$core_items = array(
'index.php' => 2, // Dashboard
'edit.php' => 5, // Posts
'upload.php' => 10, // Media
'edit.php?post_type=page' => 20, // Pages
'edit-comments.php' => 25, // Comments
'themes.php' => 60, // Appearance
'plugins.php' => 65, // Plugins
'users.php' => 70, // Users
'tools.php' => 75, // Tools
'options-general.php' => 80, // Settings
);
// Separate core and non-core items
$non_core_items = array();
foreach ( $menu as $key => $item ) {
// Skip separators
if ( $item[4] === 'wp-menu-separator' ) {
continue;
}
// If this is not a core menu item, store it for later
if ( ! array_key_exists( $item[2], $core_items ) ) {
$non_core_items[] = $item;
unset( $menu[$key] );
}
}
// Add a separator after core items
$menu[95] = array( '', 'read', 'separator-custom', '', 'wp-menu-separator' );
// Add non-core items starting at position 120
$position = 120;
foreach ( $non_core_items as $item ) {
$menu[$position] = $item;
$position++;
}
// Sort the menu by key to ensure proper ordering
ksort($menu);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment