wordpress - add_submenu_page doesn't display submenu if menu slug is the same as in top menu -


i'm trying create top menu , submenu, prevent duplicating top menu in submenu, i'm setting submenu menu_slug same in top menu. why submenu not displayed @ in case?

add_action("admin_menu", "setup_theme_admin_menus");      function setup_theme_admin_menus() {         add_menu_page('theme settings', 'example theme', 'manage_options',            'tut_theme_settings', 'theme_settings_page');        add_submenu_page('tut_theme_settings',            'front page elements', 'front page', 'manage_options',            'tut_theme_settings', 'theme_front_page_settings');    }        // handler top level menu function theme_settings_page() {   }    function theme_front_page_settings() {     echo "some text of submenu page";   }   

that's default behavior, see $menu_slug documentation add_submenu_page:

if want not duplicate parent menu item, need set name of $menu_slug same parent slug.

the problem putting same slug merges callback menu , submenu.


you may need manipulate global $submenu variable achieve goal, note gave different slug submenu:

add_action( 'admin_menu', 'setup_theme_admin_menus' );      function setup_theme_admin_menus()  {         add_menu_page(         'theme settings',          'example theme',          'manage_options',            'tut_theme_settings',          'theme_settings_page'     );        add_submenu_page(         'tut_theme_settings',       // parent slug         'front page elements 2',    // page title         'front page 2',             // menu title         'manage_options',           // capability         'tut_theme_settings2',      // slug         'theme_front_page_settings' // callback     );        // remove submenu created add_menu_page     global $submenu;     unset( $submenu['tut_theme_settings'][0] ); }   

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -