1

I am adding Custom Post Types to my wordpress dashboard. When a new CPT is added it is added to the bottom of the menu. I would prefer for the CPT menu items to be in alphabetical order.

For example, in the image below I added a new CPT called 'Animations / Films / Aerials' and it is inserted at the bottom of the menu order:

enter image description here

What solutions have I looked for before posting? I have looked for answers on stack but I haven't found a clear solution. I also read through the documentation here: https://codex.wordpress.org/Function_Reference/register_post_type#Parameters. It seems like the menu-position property doesn't allow you to change the order of CPT's relative to one another. What needs to be done if I want these CPT's to be in alphabetical order in the admin menu?

1 Answer 1

1

Here is an example of one way I have managed to edits those:

function wpse_custom_menu_order( $menu_ord ) {
    if ( !$menu_ord ) return true;

    return array(
        'index.php', // Dashboard
        'separator1', // First separator
        'edit.php', // Posts
        'upload.php', // Media
        'link-manager.php', // Links
        'edit-comments.php', // Comments
        'edit.php?post_type=page', // Pages
        'separator2', // Second separator
        'themes.php', // Appearance
        'plugins.php', // Plugins
        'users.php', // Users
        'tools.php', // Tools
        'options-general.php', // Settings
        'separator-last', // Last separator
    );
}
add_filter( 'custom_menu_order', 'wpse_custom_menu_order', 10, 1 );
add_filter( 'menu_order', 'wpse_custom_menu_order', 10, 1 );

More info:

https://developer.wordpress.org/reference/hooks/custom_menu_order/ https://developer.wordpress.org/reference/hooks/menu_order/

I have found using this plugin to be the smoothest also you can poke around the code to see how they do it: https://wordpress.org/plugins/admin-menu-editor/. Its a free plugin!

2
  • Thanks for the information, much appreciated. Mar 27, 2020 at 20:56
  • Of course hope it helps!
    – mikerojas
    Mar 27, 2020 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.