admin管理员组

文章数量:1389754

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:

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: . 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?

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:

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/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?

Share Improve this question asked Mar 27, 2020 at 20:43 Joel HoeltingJoel Hoelting 1375 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/reference/hooks/custom_menu_order/ https://developer.wordpress/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/plugins/admin-menu-editor/. Its a free plugin!

本文标签: Custom Post TypesChange order of menu items