1

It is possible to add the menu for a custom post type beneath another menu (in my case a custom one that I have created) but this appears as the first item.

How exactly do I move this to a different position - say 2nd or 3rd in the list?

Wordpress advises:

Note: When using 'some string' to show as a submenu of a menu page created by a plugin, this item will become the first submenu item, and replace the location of the top-level link. If this isn't desired, the plugin that creates the menu page needs to set the add_action priority for admin_menu to 9 or lower.

However how exactly do I apply this?

I'm a bit stuck for an answer on this one. The function add_menu_page() allows a numerical position argument but this is for the top level position. The function add_submenu_page() doesnt seem to allow a position to be set.

TIA

  • in the hook "admin_menu", you can read $GLOBALS["wp_menu"] and $GLOBALS["wp_submenu"] and reorder them – mmm Oct 13 '17 at 22:23
  • Thanks @mmm much appreciated, just one follow-up - here you list the variables as prefixed with "wp_", my $GLOBALS array omits these, just using keys as "menu" and "submenu". Does this mean there is some variability that one needs to account for? And as such is there a convenient way to check? (and then we dive down the rabbit warren!) – Shaun Mc Oct 14 '17 at 11:33
  • yes you are right, the good arrays are $GLOBALS["menu"] and $GLOBALS["submenu"] – mmm Oct 14 '17 at 11:46
0

Fixed and here's how, please excuse the unedited cut and paste, thanks to @mmm for the pointers on how:

  1. Add Custom Post Type via Action

    add_action('init', array($this, 'mactrak_custom_post_type_add'));

  2. Above function as called (mactrak_custom_post_type_add) includes argument to set up meta box and menu position

  3. Following construct:

    add_action('admin_menu', array(&$this,'mactrak_admin_menu'));

  4. runs following script:

    add_menu_page( 'MacTrak - the WP FindMeSpot Interface', 'MacTrak', 'edit_posts', 'wp_mactrak_admin_menu', array($this,'mactrak_admin_main'),'dashicons-location-alt', 30);

    $customMarkerTemp = array_pop($GLOBALS['submenu']['wp_mactrak_admin_menu']); // Remove Custom Marker Item from Sub menu

    add_submenu_page( 'wp_mactrak_admin_menu', 'MacTrak - the WP FindMeSpot Interface', 'My Tracker Map', 'edit_posts', 'wp_mactrak_admin_menu', array($this,'mactrak_admin_main')); add_submenu_page( 'wp_mactrak_admin_menu', 'MacTrak - FindMeSpot Data', 'FindMeSpot Data', 'edit_posts', 'wp_mactrak_admin_fmsdata', array($this,'mactrak_admin_fmsdata')); add_submenu_page( 'wp_mactrak_admin_menu', 'MacTrak - Custom Flight Lines', 'Custom Flight Lines', 'edit_posts', 'wp_mactrak_admin_customlines', array($this,'mactrak_admin_customlines')); $GLOBALS['submenu']['wp_mactrak_admin_menu'][] = $customMarkerTemp; // Reinsert Custom Markers item in order add_submenu_page( 'wp_mactrak_admin_menu', 'MacTrak - Current Location', 'Current Location', 'edit_posts', 'wp_mactrak_admin_currentloc', array($this,'mactrak_admin_currentloc')); add_submenu_page( 'wp_mactrak_admin_menu', 'MacTrak - Settings', 'Settings', 'edit_pages', 'wp_mactrak_admin_settings', array($this,'mactrak_admin_settings'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.