Saturday, October 15, 2011

How to add menu to admin side bar

In this tutorial i will show you how to add a menu item in admin menu.Wordpress has made the process very simple we just have to call few hooks and write few lines of code.The code for this will also be stored in wordpress plugin directory.

How to do it?
1-Make a folder in wordpress -> wp-content -> plugins
2-Make a php file and put the file inside it.
3-Then go to admin panel and look at the link it would be there.



In our example we will have a folder called admin-menu and php file admin-menu.php.

Code for adim-menu.php
< ?php
/*
Plugin Name: Admin Menu
Plugin URI: http://wp-help.blogspot.com/
Description: Admin Menu
Author: zalmai khan
Author URI: http://wp-help.blogspot.com/
*/

// Hook for adding admin menus
add_action('admin_menu', 'mt_add_pages');

// action function for above hook
function mt_add_pages() {

// Add a new top-level menu (ill-advised):
add_menu_page(__('Your Menu Title'), __('Your Menu name'), 'manage_options', 'mt-top-level-handle', 'mt_toplevel_page' );

}

// mt_toplevel_page() displays the page content for the custom Test Toplevel menu
function mt_toplevel_page() {
echo "

" . __( 'page contents for the menu' ) . "

";
}

?>

4 comments:

  1. This is best way to add menu item to wordpress...

    ReplyDelete
  2. I did everything as explained but I see no menu added to the admin sidebar.

    Am I missing something? Please help.

    Thanks so much

    ReplyDelete



  3. It was really an amazing blog post and I was really impressed by reading this blog.

    WordPress Tech Support

    ReplyDelete
  4. not working tried it and cross check it also

    ReplyDelete