WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Creating an admin menu (5 posts)

  1. Dave Navarro, Jr.
    Member
    Posted 2 years ago #

    I created some custom Shortcodes and Filters for a site as a plugin and I'm trying to add an admin menu for some options using the following code:

    /* Create Admin Menu and Options Submenu */
    function td_options_page() {
      ?>
    
      <div class="wrap"><?php screen_icon(); ?>
      <h2>Topeka Design Extensions for WIBW</h2>
      <p>Options Page</p></div>
    
      <?php
    }
    function td_register_admin_panel() {
      add_menu_page('Options', 'Topeka Design', 'manage_options', 'topeka-design', 'td_options_page');
    }
    add_action('admin_menu', 'td_register_admin_panel');
    
    /* Create Help Submenu */
    function td_help_page() {
      ?>
    
      <div class="wrap"><?php screen_icon(); ?>
      <h2>Topeka Design Extensions for WIBW</h2>
      <p>Help</p></div>
    
      <?php
    }
    function td_register_help_submenu_page() {
    	add_submenu_page( 'topeka-design', 'Help', 'Help', 'manage_options', 'td-help-page', 'td_help_page' );
    }
    add_action('admin_menu', 'td_register_help_submenu_page');

    However the first sub-menu displayed is "Topeka Design" and not "Options".

    I've been through the codex numerous times and I'm not seeing what I'm doing wrong. A little help would be appreciated.

  2. mattyrob
    Member
    Posted 2 years ago #

    In your add_menu_page() function the first parameter is the page title (in the HTML title tags), the second parameter is the title of the menu is the menu system.

    Try changing that second parameter to "Options".

    http://codex.wordpress.org/Function_Reference/add_menu_page

  3. Dave Navarro, Jr.
    Member
    Posted 2 years ago #

    add_menu_page('Options', 'Topeka Design', 'manage_options', 'topeka-design', 'td_options_page');

    This ends up being {Topeka Design}->Topeka Design

    add_menu_page('Topeka Design', 'Options', 'manage_options', 'topeka-design', 'td_options_page');

    This ends up being {Options}->Options

    add_menu_page('Options', 'Options', 'manage_options', 'topeka-design', 'td_options_page');

    This ends up being {Options}->Options

    It appears the first parameter is ignored and the second parameter is used twice.

  4. bcworkz
    Member
    Posted 2 years ago #

    The $page_title parameter that appears to be ignored has nothing to do with the appearance of the menu. It is the string placed inside the <title> tags in the <head> section of the admin panel being displayed when the menu item is selected.

    To stop the replication of the main menu item in the sub menus, the first added sub menu's $menu_slug needs to be identical to the $parent_slug.

    I'm not sure what's going on yet, but this duplication no longer seems to be an issue in my 3.5.1 installation. But now the main menu link is matching the first sub menu and the main menu link is unavailable. YMMV?

  5. Dave Navarro, Jr.
    Member
    Posted 2 years ago #

    Bizarre... I created the menu, then created a sub-menu page using the same slug and it worked.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.