Skip to content

Instantly share code, notes, and snippets.

@mindctrl
Last active November 14, 2025 12:00
Show Gist options
  • Select an option

  • Save mindctrl/1fc45d251676fa0191cbe1df5373ea25 to your computer and use it in GitHub Desktop.

Select an option

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 ( $item[2] === 'wpforms-overview' ) {
$item[0] = 'Forms';
remove_submenu_page( 'wpforms-overview', 'wpforms-analytics' );
remove_submenu_page( 'wpforms-overview', 'wpforms-smtp' );
remove_submenu_page( 'wpforms-overview', 'wpforms-about' );
remove_submenu_page( 'wpforms-overview', 'wpforms-community' );
remove_submenu_page( 'wpforms-overview', 'wpforms-wpconsent' );
}
if ( $item[2] === 'wp-mail-smtp' ) {
$item[0] = 'SMTP';
remove_submenu_page( 'wp-mail-smtp', 'wp-mail-smtp-logs' );
remove_submenu_page( 'wp-mail-smtp', 'wp-mail-smtp-reports' );
remove_submenu_page( 'wp-mail-smtp', 'wp-mail-smtp-about' );
}
// 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] );
}
}
global $submenu;
unset( $submenu['wp-mail-smtp'][5] );
// 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);
}
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'jp_menu_order' );
/**
* Reorder the admin menu
*
* @param array $menu_order The menu order
* @return array The menu order
*/
function jp_menu_order( $menu_order ) {
$menu_order[] = 'googlesitekit-dashboard'; // Site Kit uses `menu_order` to force its item up top 👎
$menu_order[] = 'wpforms-overview';
$menu_order[] = 'wp-fail2ban-menu';
$menu_order[] = 'wpseo_dashboard';
$menu_order[] = 'wp-mail-smtp';
return $menu_order;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment