30
Jul
How to add admin menu in wordpress
- Category:
- Wordpress
Posted On : July 30, 2013
| No Comment
Many times it is needed to create menu on admin side in wordpress. Mainly needed when we create any plugin, or created any admin page.
Create admin menu using provided functions by wordpress :
Code 1:
View Code PHP
1 2 3 4 5 | //in theme’s function.php file add_action('admin_menu', 'myadminmenu'); function myadminmenu() { add_menu_page( 'demo menu', 'demo menu', 1, 'demo_menu', 'createmenu' ); //display Top-Level menu } |
Code 1:
View Code PHP
1 2 3 4 | function createmenu(){ //content of admin menu page echo "Demo Menu Page"; } |
Screenshot :
Can also display submenu under any available menus :
View Code PHP
1 2 3 | //display submenu under dashboard menu add_submenu_page( 'index.php', 'demo menu', 'demo menu', 1, 'demo_menu', 'createmenu'); OR add_dashboard_page( ‘$page_title’, ‘menu_title’, ‘$capability’, $menu_slug, function_name); |
View Code PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 | //display submenu under Posts menu add_submenu_page( 'edit.php', 'demo menu', 'demo menu', 1, 'demo_menu', 'createmenu'); OR add_post_page( ‘$page_title’, ‘menu_title’, ‘$capability’, $menu_slug, function_name); //display submenu under Settings menu add_submenu_page( ' options-general.php', 'demo menu', 'demo menu', 1, 'demo_menu', 'createmenu'); OR add_ options_page( ‘$page_title’, ‘menu_title’, ‘$capability’, $menu_slug, function_name); Ex : add_options_page('demo menu', 'demo menu', 1, 'demo_menu', 'createmenu'); //display submenu under Users menu add_submenu_page( ' users.php', 'demo menu', 'demo menu', 1, 'demo_menu', 'createmenu'); OR add_ users_page( ‘$page_title’, ‘menu_title’, ‘$capability’, $menu_slug, function_name); Ex : add_options_page('demo menu', 'demo menu', 1, 'demo_menu', 'createmenu'); |
- Tags: