How to Customize Menu Order for WordPress Admin Submenu Items

Organizing the WordPress admin dashboard is essential for improving productivity and user experience. Often, the default order of admin submenu items may not align with your workflow. WordPress provides a powerful hook, custom_menu_order, to rearrange both menu and submenu items in the admin panel. This blog will guide you through the process of customizing admin submenu items in detail.

WordPress Care and Development Plans

What is custom_menu_order?

The custom_menu_order filter is a WordPress hook that allows developers to override the default order of admin menu items. By activating this filter and defining a new order, you can control how menus and submenus are displayed in the dashboard.

Why Reorder Admin Menu and Submenu Items?

Customizing the admin menu order offers several benefits:

  1. Improved Navigation: Simplifies access to frequently used menu items.
  2. Streamlined Workflow: Prioritizes menu items based on usage frequency.
  3. Enhanced User Experience: Offers a tailored dashboard experience for site administrators.
  4. Brand Consistency: For client projects, you can organize menus to present a polished, client-focused dashboard.

Key Steps to Customize Submenu Order

Step 1: Enable custom_menu_order

To start reordering menus, activate the custom_menu_order filter in your theme’s functions.php file:

php
add_filter(‘custom_menu_order’, ‘__return_true’);
add_filter(‘menu_order’, ‘customize_admin_menu_order’);

Step 2: Create the Menu Order Function

Define a function to specify the new menu order:

php
function customize_admin_menu_order($menu_order) {
return [ ‘index.php’, // Dashboard
‘edit.php’, // Posts
‘upload.php’, // Media
‘edit.php?post_type=page’, // Pages
‘themes.php’, // Appearance
‘plugins.php’, // Plugins
‘users.php’, // Users
‘tools.php’, // Tools
‘options-general.php’ // Settings
]; }
  • Each menu item is identified by a slug, such as index.php for the Dashboard.
  • Add or reorder menu items based on your preferences.

Customizing Submenus

Reordering submenus is slightly different as it requires targeting specific menu slugs and rearranging their items.

Example: Reordering Pages Submenu Items

The Pages menu contains submenus like “All Pages” and “Add New.” To reorder these:

  1. Access the global $submenu variable.
  2. Rearrange submenu items within the desired menu.
php
function reorder_pages_submenu()
{ global $submenu;
if (isset($submenu[‘edit.php?post_type=page’])) {
$submenu[‘edit.php?post_type=page’] = [
$submenu[‘edit.php?post_type=page’][2], // All Pages
$submenu[‘edit.php?post_type=page’][1], // Add New
];
}
}
add_action(‘admin_menu’, ‘reorder_pages_submenu’, 999);

This snippet identifies submenu items under the “Pages” menu and swaps their positions.

Identifying Menu and Submenu Slugs

To reorder menus, you need their slugs. Use one of these methods:

  1. Admin Menu Inspector: Install a plugin like Admin Menu Editor to view menu slugs.
  2. Check the Source Code: Inspect the admin menu HTML in your browser’s developer tools.
  3. WordPress Codex: Refer to documentation for common slugs.

Using Plugins for Menu Reordering

For non-developers or complex requirements, plugins simplify the process:

1. Admin Menu Editor

  • Drag and drop menus into your desired order.
  • Hide or rename menu items.
  • Restrict access based on user roles.

2. White Label CMS

  • Customize menus as part of a broader branding effort for the WordPress dashboard.

Advanced Customizations with User Role-Specific Menus

Reorder menus dynamically based on user roles to create personalized experiences for administrators, editors, or contributors.

php
function role_based_menu_order($menu_order) {
if (current_user_can(‘editor’)) {
return [
‘edit.php’, // Posts
‘upload.php’, // Media
‘edit-comments.php’, // Comments
];
} else {
return $menu_order; // Default order for other roles
}
}
add_filter(‘menu_order’, ‘role_based_menu_order’);

Best Practices for Reordering Admin Menus

  1. Backup Your Site: Always back up your site before editing core files or themes.
  2. Use a Child Theme: Apply changes in a child theme to prevent overwrites during updates.
  3. Keep the Order Logical: Ensure menus follow a sequence that makes sense for all users.
  4. Test Across User Roles: Verify menu accessibility for different roles to avoid accidental restrictions.

FAQs

1. Can submenu items be reordered without plugins?

Yes, you can use custom PHP code in your theme’s functions.php file to reorder submenu items.

2. Will customizations persist after a theme update?

Not unless you use a child theme or a custom plugin.

3. Are there risks in modifying admin menus?

Poorly written code can break the admin interface or restrict access to essential features. Always test changes on a staging site first.

BuddyX Theme

Conclusion

Reordering admin submenu items using the custom_menu_order hook is a straightforward yet powerful way to enhance the usability of your WordPress dashboard. Whether through custom code or user-friendly plugins, you can tailor the admin interface to better suit your workflow. By following the steps outlined above, you’ll create a streamlined, efficient environment for managing your WordPress site.


Interesting Reads:

Best WordPress Social Bookmark Plugins for 2024 (Expert Picks)

Best AI Inventory Management Software Of 2024

How to Remove Parent Slug From Child Page URL in WordPress?

Facebook
Twitter
LinkedIn
Pinterest