admin管理员组

文章数量:1201975

Adding sub menus is easy with add_submenu_page and is working fine as long if you define a $parent_slug:

add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );

if you set the $parent_slug to NULL as described here to hide it from any menu item the title of the page will get ignored ($page_title)

add_submenu_page( NULL, $page_title, $menu_title, $capability, $menu_slug, $function );

I've tested it with all versions from 3.3 up to the latest 4.0

Adding sub menus is easy with add_submenu_page and is working fine as long if you define a $parent_slug:

add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );

if you set the $parent_slug to NULL as described here to hide it from any menu item the title of the page will get ignored ($page_title)

add_submenu_page( NULL, $page_title, $menu_title, $capability, $menu_slug, $function );

I've tested it with all versions from 3.3 up to the latest 4.0

Share Improve this question edited Sep 10, 2014 at 12:59 Xaver asked Sep 10, 2014 at 11:15 XaverXaver 1,0393 gold badges13 silver badges29 bronze badges 5
  • ... Drumroll... And your question is?.... :-) – Pieter Goosen Commented Sep 10, 2014 at 11:54
  • Sorry, I've updated the headline – Xaver Commented Sep 10, 2014 at 12:59
  • Your question should be in the body, not in the title :-) – Pieter Goosen Commented Sep 10, 2014 at 13:18
  • 1 that is still not a question with a meaningful answer. the answer is "because whoever wrote the code thought it should be done that way" – Mark Kaplun Commented Sep 10, 2014 at 14:04
  • I think this a legit question, shouldn't the <title> tag be set regardless of whether the page has a parent or not. Perhaps this is a bug report for WP? – Ben Commented Feb 26, 2021 at 11:43
Add a comment  | 

1 Answer 1

Reset to default 0

It is a valid question and an issue I have encountered as well.

I did not go through the WP core code to see why the title is missing, but I can offer a solution using the admin_title filter, for people facing a similar problem:

function fix_your_page_title( $admin_title, $title ) {
    if ( get_current_screen()->id === 'your_page_id' && $title === '' ) {
        $admin_title = 'Your page title' . $admin_title;
    }    

    return $admin_title;
}

add_filter( 'admin_title', 'fix_your_page_title', 10, 2 );

本文标签: Why is the Page Title missing on Pages added with addsubmenupage