Reputation: 3195
I am using WP 3.6.
I am building a theme that only needs a few of the 'native' admin menu items and one menu item I have added using 'add_object_page'.
I would like to make my menu item ALWAYS be the first item.
How can I force it to appear at the top of the list above all plugins and the 'native' menu items?
Upvotes: 0
Views: 827
Reputation: 1260
If you want the item to appear at the top above the dashboard. you need to add it as a menu page. with position 1.
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null )
this will make it appear on the top.
when you add it as an object page, it is automatically given the lowest position. Note: need to use the admin_menu hook.
**=============or===============**,
you can use the custom_menu-order and menu_order hook and reorder the menu items.
eg:
function order_menu ($order)
{
//$order is an array of slug of menu items, reorder
//reorder it as you would want to appear in the admin menu.
$page_slug="dolt";
unset($order[array_search($page_slug,$order)]);
array_unshift($order,$page_slug);
return $order;
}
add_filter('custom_menu_order',function(){return true;});
add_filter('menu_order','order_menu',11);
Upvotes: 1
Reputation: 1011
You can use add_menu_page() with last parameter $position.
The position in the menu order this menu should appear. By default, if this parameter is omitted, the menu will appear at the bottom of the menu structure. The higher the number, the lower its position in the menu. WARNING: if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays! Risk of conflict can be reduced by using decimal instead of integer values, e.g. 63.3 instead of 63 (Note: Use quotes in code, IE '63.3').
Default: bottom of menu structure
Positions for Core Menu Items:
2 Dashboard
4 Separator
5 Posts
10 Media
15 Links
20 Pages
25 Comments
59 Separator
60 Appearance
65 Plugins
70 Users
75 Tools
80 Settings
99 Separator
For More: visit WordPress Codex
Upvotes: 2