I made it possible to use post-new.php?post_cat=catslug in the wordpress admin for creating a new post with a pre-filled category by using the answer here:
How to add category to: ‘wp-admin/post-new.php’?
Now I want to create multiple menu items with this format under the “Posts” -> “Add new” admin menu item. So the menu will be:
POSTS
- All posts
- Add New
- Add New Profile -> post-new.php?post_cat=profile
- Add New News -> post-new.php?post_cat=news
- Add New Pitch ->post-new.php?post_cat=pitch
- Categories
- etc.
I have been able to add one item to the bottom of the menu with this code in functions.php
add_action( 'admin_menu' , 'admin_menu_new_items' );
function admin_menu_new_items() {
global $submenu;
$submenu['edit.php'][500] = array( 'Add new profile', 'manage_options' , '/wp-admin/post-new.php?post_cat=pitches' );
}
Questions:
- Is this the best way to do this? Or do I need to use one of the functions as described here http://codex.wordpress.org/Administration_Menus. I tried some but I couldn’t get it to work the way I want.
- If the above code is the best way to go, how do I add more items?
- How do I add the menu item below “Add new” (instead of below “tags”)
To see the the current array keys try this:
I get this:
Index ’10’ is the Add New item. To add the new sub menu items use indexes 11, 12 and 13:
When WordPress adds the sub menu items to the dashboard it treats
$submenu
as an associative array. Any items added to theedit.php
array will be added to the end of array regardless of the key used. Use ksort() to order the keys.Putting it all together: