There are different Ways to add Navigation Points to the WordPress Backend, most of them are explained here. Basically you have:
add_options_page
This will basically create another navigation Point under setting as most Plug-ins do. Its best suited for scenarios where your Plug-in provides Options/Settings for your blog.
The Parameters are the following
- the Title you want to display in the Menu
- the Title you want to display on the Page itself
- the Userlevel required to see the Link
- as the name says, a unique string, basename(__FILE__) works just fine also
- a callback function for the page it should lead to, you can use a simple function name (as string) or use an object and its method, as i did
the syntax could look like:
add_options_page('Menu Title', 'Page Title', 9,'an-uniq-string-as-key', array('wp_my_awesome_class','optionPage'));
add_submenu_page
As the Name suggests this function is used to add Sub Menus to any Main Option, besides and including what add_options_page does, why are there two different functions then? Lets say legacy Reason – yeah sounds fine.
As you may see, its basically the same, besides you need to give the unique-key of the parent you want to attend to, for the basics that would be:
For Write: add_submenu_page(‘post-new.php’,…)
For Manage: add_submenu_page(‘edit.php’,…)
For Design: add_submenu_page(‘themes.php’,…)
For Comments: add_submenu_page(‘edit-comments.php’,…)
For Settings: add_submenu_page(‘options-general.php’,…)
For Plugins: add_submenu_page(‘plugins.php’,…)
For Users: add_submenu_page(‘users.php’,…)
Or, anything you set up as a Main-Menu-Point / Parent yourself.
And it, for an example, looks like:
add_submenu_page('an-uniq-string-as-key-of-the-parent','Page Title','Menu Title',9,'an-uniq-string-as-key', array('wp_my_awesome_class','adminPage'));
add_menu_page
And thats where the fun starts, with this nice function you can add a Main-Navigation-point to your menu.
The most stuff should be clear by now, the only difference is that you add a path to an icon you use. Well, isnt that just too nice to be true? Yes, yes it is, because you will notice that your Nice new so important Main Navigation Point will always appear on the very bottom of the Navigation.
So lets, see, in the End you can add Navigation Points to every Main Navigation Points (in the Bottom) and an Main Navigation Point itself, in the bottom.
the syntax could look like:
add_menu_page('Page Title', 'Main Title',4,'an-uniq-string-as-key', array('wp_my_awesome_class','adminPage')),'http://www.example.com/favicon.ico');
Now, if you want to Add an Main Navigation Point on another Position it is possibile, but only in a not documented manner!
add_menu_page extended
The Code is the same as for the regular use of add_menu_page, but in release 2.9 they added a new Parameter that can be used to choose the Position of the Entry:
add_menu_page('Page Title', 'Main Title',4,'an-uniq-string-as-key', array('wp_my_awesome_class','adminPage')),'http://www.example.com/favicon.ico',1);
This would then Appear on top, even before Dashboard. However, unfortunately you can not just use every Position.
Since most of them are already taken by Existing Menu Points and Separators if you do so anyway you’ll overwrite them.
Some free Positions you can use are: 1,3,6,7,8,9,11,12,13,14,16,17,18,19.
If you want to be more free you must do the following, first we must activate the “custom_menu_order” Hook.
Just add this Code in a Plugin, of the functions.php of your template:
add_filter('custom_menu_order','custom_menu_order_function');
function custom_menu_order_function(){
return true;
}
Now we can use the menu_order Filter to add our an-uniq-string-as-key at any position we want
add_filter('menu_order','menu_order_my_function');
function menu_order_my_function($menu_order){
$new_menu_order = array();
foreach($menu_order as $position => $menu_element){
if($position == 4){
$new_menu_order[] = 'an-uniq-string-as-key';
}elseif($menu_element != 'an-uniq-string-as-key'){
$new_menu_order[] = $menu_element;
}
}
return $new_menu_order;
}
4 is of course the example Position, you can use any you want. To move separators just use the strings “separator1″, “separator2″ and “separator-last” unfortunately it seams you can only move the existing Separators, not add new ones.
But like i said, this is not documented, so use it carefully if you choose so. And most important, think if your Plug-in “add-alt-seo-title-to-dohikkie” really need the number one Position.
Access Limitations
You See in all this functions always an numeric value for the Access Rights, wich value Reflects witch user type you can see at the Capability vs. Role Table
24. Juni 2010 um 17:07 Uhr
Hi
thanks for this impressive tuts! really useful!
I would like to place the media menu after the page menu.Have you an idea?
I don’t know I miss something?
thanks!
29. Juni 2010 um 15:55 Uhr
Hi Nicolas,
thanks for the compliment, honestly that tutorial relates to wordpress 2.9 so i don’t know if its a 100% on 3.0 but it should.
Okay what you have to follow is the steps in ‘add_menu_page extended’ look at the last 2 code blocks, first you enable the ‘custom_menu_order’ filter :
add_filter(‘custom_menu_order’,'custom_menu_order_function’);
function custom_menu_order_function(){
return true;
}
After that you can override the default wordpress Function for sorting:
add_filter(‘menu_order’,'menu_order_my_function’);
function menu_order_my_function($menu_order){
// do whatever you want
return $new_menu_order;
}
the $menu_order array holds all Menu Elements, and their order represents the order inside the menu, so just change it here however you want.