Add menu,sub menu,top level menu of our plug in on admin panel of word press
Here we learn how to add the menu to word press admin side panels to control our plug ins functionality like settings ,over view etc.
Download Demo
Word press comes with some admin menus by default ,listed below
- Dash board- To get the over view of blog on the admin home page.
- Posts – mainain the blog posts
- Media – manage media files on blog
- Links-blogs default links
- Pages-manage blog pages
- Comments-manage blog comments
- Appearence -maintain blog themes and blog theme settings.
- Plugins - manage blog plug ins
- Users- manage blog users for admins and registered users
- Tools-manage database and files back up.
- Settings – blogs over all settings
To continue this tutorial we must aware about
- word press hooks ,filters and their functions.
- PHP OOP’s concepts
Okay, no problem even you don’t know much about word press hooks,we can manage with a main action hook for this tutorial.
admin_menu action
This action was triggered before admin menu begins and here we can add our menus .
Let start over view of the our plugin
We define the class for our plugin and instantiate it.
In the constructor our class we attach the admin_menu hook as below,that runs our class method my_admin_menu
add_action('admin_menu', array(&$this, 'my_admin_menu'));
Add our own panel with add_menu_page

add_menu_page(‘Panel Title’, ‘Panel first sub link title ‘, ‘level of handler ‘,’unique identifier for page’,'function that to be called’));
In the above line add_menu_page adds the main panel on the word press admin page.
add_menu_page('Mahesh Chari', 'Mahesh Chari', 'administrator', 8, array(&$this,'overview'));
Adding our sub links to own panel
Now we add sub links above panel titled settings, general with unique identifiers.
add_submenu_page(8, 'Settings', 'Settings', 'administrator', 1, array(&$this,'settings')); add_submenu_page(8, 'General', 'General', 'administrator', 2, array(&$this,'generel'));
Now we add our plug ins link to existing word press panels mentioned above
Word press has already pre built functions to add respective panels.
Add sub menu link to existing posts panel
add_posts_page('Mahesh posts', 'Mahesh Plugin', 'administrator', basename(__file__), array(&$this, 'my_plugin_posts'));
Add sub menu link to existing Media panel
add_media_page('Mahesh media', 'Mahesh Plugin', 'administrator', basename(__file__), array(&$this, 'my_plugin_media'));
Add sub menu link to existing pages panel
add_pages_page('Mahesh pages', 'Mahesh Plugin', 'administrator', basename(__file__), array(&$this, 'my_plugin_pages'));
Add sub menu link to existing appearance panel
add_theme_page('maheshchari', 'Mahesh Plugin', 'administrator', basename(__file__), array(&$this, 'my_plugin_themes'));
Add sub menu link to existing users panel
add_users_page('Mahesh users', 'Mahesh Plugin', 'administrator', basename(__file__), array(&$this, 'my_plugin_users'));
Add sub menu link to existing tools panel
add_management_page('maheshchari', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_tools'));
Add sub menu link to existing options panel
add_options_page('Mahesh Options', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_options'));
Together all the sub menus
<?php /* Plugin Name: Mahesh Chari Plugin URI: http://www.maheshchari.com/ Description: Description of my plugin Author URI: http://www.maheshchari.com/ */ class Maheshchari { function Maheshchari() { add_action('admin_menu', array(&$this, 'my_admin_menu')); } function my_admin_menu() { //create a main admin panel //create a sub admin panel link above add_menu_page('Mahesh Chari', 'Mahesh Chari', 'administrator', 8, array(&$this,'overview')); add_submenu_page(8, 'Settings', 'Settingss', 'administrator', 1, array(&$this,'settings')); add_submenu_page(8, 'Generel', 'Generel', 'administrator', 2, array(&$this,'generel')); //These functions adds sub menu for different kinds of admin panel on back end add_options_page('Mahesh Options', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_options')); add_posts_page('Mahesh posts', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_posts')); add_media_page('Mahesh media', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_media')); add_pages_page('Mahesh pages', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_pages')); add_users_page('Mahesh users', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_users')); add_management_page('maheshchari', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_tools')); add_theme_page('maheshchari', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_themes')); } function overview() { echo '<h2>My Wordpress Plugin Overview</h2>'; } function settings() { echo '<h2>My Wordpress Plugin Settings</h2>'; } function generel() { echo '<h2>My Wordpress Plugin Generel</h2>'; } function my_plugin_options() { echo '<h2>My Wordpress Plugin Options</h2>'; } function my_plugin_posts() { echo '<h2>My Wordpress Plugin posts</h2>'; } function my_plugin_media() { echo '<h2>My Wordpress Plugin media</h2>'; } function my_plugin_pages() { echo '<h2>My Wordpress Plugin pages</h2>'; } function my_plugin_users() { echo '<h2>My Wordpress Plugin users</h2>'; } function my_plugin_tools() { echo '<h2>My Wordpress Plugin tools</h2>'; } function my_plugin_themes() { echo '<h2>My Wordpress Plugin themes</h2>'; } } $mybackuper = &new Maheshchari();//instance of the plugin class ?>
To see the above code inaction,please download the zip of demo plug in and copy to your word press plug ins directory and activate the plugin ,then you see all the sub menus in admin panels menu
Download the Demo
Popularity: 20% [?]









Related Articles
5 users responded in this post
[...] A detailed overview about adding custom menus wordpress admin panels | Php Development [...]
[...] we successfully created our plugin and next adding sub menu on admin panel of word press . AKPC_IDS += "501,";Popularity: unranked [?] Share and [...]
[...] have already learned that how to add all available menu ,sub menu to word press plug in. Now we learn how to add our themes option menu to word press admin [...]
[...] the rest here: A detailed overview about adding custom menus wordpress admin panels | Php Development Tags: menu, [...]
Hi,
This is a message for the webmaster/admin here at http://www.maheshchari.com.
Can I use part of the information from this blog post right above if I give a backlink back to your website?
Thanks,
Daniel
Leave A Reply