Problem with custom CPT menu in WP

I have two CPTs like "Dress" and "Casual", and I would like to place them close to each other precisely after the "Dashboard" in the menu.

I have this code in my custom message type for both:

'menu_position'       => 2

as if the result would be displayed as: enter image description here

Positions "Mail" after "Dresses"! can you tell me why this is happening and how i can save all CPT in front of each other until "Post". (I have 5 custom post types)

thanks

+4
source share
2 answers

Wordpress menu_position, , . , Dashboard 2, 4, , 6 ( 5)..

, , , , menu_position, , .

WP , , .

menu_position 6 7 , , 8 9 -

add_action('admin_head', 'my_edit_admin_menu');
function my_edit_admin_menu(){

    global $menu;

    $menu[8] = $menu[4];  // Copy 'separator1' to a new menu location
    unset($menu[4]);      // Unset separator1 (from original position)

    $menu[9] = $menu[5];  // Copy 'Posts' to a new menu location
    unset($menu[5]);      // Unset Posts (from original position)

    ksort($menu);         // Sort the menu

}

- admin_head ( init). - , menu_position . , WP , .

. menu_position Arguments register_post_type() WP ( , 3.8). , , , -

echo '<pre>WP Admin Menu: '; print_r($menu); echo '</pre>';

FYI. , . WP 3.8, admin DashIcons.

, , menu_icon, . , , ; , dashicons-menu.

+3

Source: https://habr.com/ru/post/1524230/


All Articles