w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
WordPress Admin: When placing a Custom Post Type as a submenu of a parent menu, the parent menu link is being overridden by the CPT

can't say, what's exactly the reason, but it seems wordpress redirects to the first submenu-item.

So you have to create a new sub-menu-item with the same contents of your parent-menu-item.

add_action('admin_menu', 'my_admin_menu');

function my_admin_menu() {
    global $submenu;
    add_menu_page('My Menu', 'My Menu', 'administrator', 'my-menu',
'callback_func');

    $parent = array('My Menu', 'administrator', 'my-menu', 'My Menu'); //
new submenu-itm
    $submenu['my-menu'] = fix_menu($submenu['my-menu'], $parent); // adds
the new submenu-item at beginning of 'my-menu'-item
}

function fix_menu($submenu) {
    array_unshift ($submenu, $parent);
    return $submenu;
}

Hope it works for you.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.