WordPress is a top CMS used by 60%+ of the Bloggers world. Its is a open source CMS so you are allowed to do anything with it. Now you know that there are many plugins that comes to make your Blogging more easly. Now those menu have there own menu bar in your WordPress dashboard after installing. Now you can also have like them.
If you are creating a plugin for WordPress and want to help others then it will be more helpful if you create a plugin and make a new menu in user WordPress admin dashboard so that he/she can do your plugin setting easily. So for this you are allowed to add menu there and also have many different places to add your menu in user WordPress admin dashboard through your plugin.
- Add Menu In Top Level Menu Items?
- Add Menu Under Top Level Items?
- Add Menu Under Dashboard Menu?
- Add Menu Under Posts Menu?
- Add Menu Under Media Menu?
- Add Menu Under Links Menu?
- Add Menu Under Pages Menu?
- Add Menu Under Comments Menu?
- Add Menu Under Custom Post Types Menu?
- Add Menu Under Appearance Menu?
- Add Menu Under Plugins Menu?
- Add Menu Under Users Menu?
- Add Menu Under Tools Menu?
- Add Menu Under Settings Menu?
So now add your Plugin menu anywhere you want but adding the below codes easily. If you want to know more about any function then WordPress Codex Page For Administrator Menu is awesome to help you more.
Table of Contents
How To Add Your Menu In Top Level Menu Items?
If your WordPress theme or plugin needs it’s own menu item then you need to add a top level menu to your WordPress admin area. To add a top level menu you need to use the WordPress function add_menu_page()
.
<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>
- $page_title – The title used on the settings page.
- $menu_title – The title used on the menu.
- $capability – Only displays the menu if the user matches this capability.
- $menu_slug – The unique name of the menu slug.
- $function – This is the callback function to run to display the page.
- $icon_url – Display a icon just for the menu.
- $position – This allows you to choose when the menu item appears in the list.
These are the positions of the menu items on the admin screen.
- 2 Dashboard
- 4 Separator
- 5 Posts
- 10 Media
- 15 Links
- 20 Pages
- 25 Comments
- 59 Separator
- 60 Appearance
- 65 Plugins
- 70 Users
- 75 Tools
If two menu items have the same position then one of them will be overwritten so only one item is displayed.
How To Add Your Menu Under Top Level Items?
These snippets will show you how you can create a new link under any of the top default menus in WordPress.
To add sub-level menus all you have to do is use the add_submenu_page()
function and pass in the parent node as the first parameter.
<?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function); ?>
- $parent_slug – This is the parent slug of the top level menu item.
- $page_title – The title to use on the page when the user clicks the link.
- $menu_title – The title of the menu.
- $capability – The capability of the user to display the menu.
- $menu_slug – The slug used for the menu.
- $function – This is the callback function to display the linked to page.
This is how to use the add_submenu_page()
function, the most important argument of this function is the $parent_slug
, this will decide where to place the submenu. All you need to do is pass in the $parent_slug
the file.php of the page you want to place the menu under.
How To Add Your Menu Under Dashboard Menu?
To add a menu item under the dashboard item.
<?php add_action('admin_menu', 'add_dashboard_menu'); function add_dashboard_menu(){ add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
All the default menu items in WordPress come with there own function to add a sub menu item, which makes it even easier to add a sub menu. To add a menu to the dashboard you can use the function add_dashboard_page()
.
<?php add_action('admin_menu', 'add_dashboard_menu'); function add_dashboard_menu(){ add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Posts Menu?
To add a menu item under the post item.
<?php add_action('admin_menu', 'add_post_menu'); function add_post_menu(){ add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the add to the posts page by using the add_posts_page()
function.
<?php add_action('admin_menu', 'add_post_menu'); function add_post_menu(){ add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Media Menu?
To add a menu item under the media item.
<?php add_action('admin_menu', 'add_media_menu'); function add_media_menu(){ add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can add to the media menu by using the add_media_menu()
function.
<?php add_action('admin_menu', 'add_media_menu'); function add_media_menu(){ add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Links Menu?
To add a menu item under the links item.
<?php add_action('admin_menu', 'add_links_menu'); function add_links_menu(){ add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the add_links_page()
function.
<?php add_action('admin_menu', 'add_links_menu'); function add_links_menu(){ add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Pages Menu?
To add a menu item under the pages item.
<?php add_action('admin_menu', 'add_pages_menu'); function add_pages_menu(){ add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the function add_pages_page()
.
<?php add_action('admin_menu', 'add_pages_menu'); function add_pages_menu(){ add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Comments Menu?
To add a menu item under the comments item.
<?php add_action('admin_menu', 'add_comments_menu'); function add_comments_menu(){ add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the add_comments_page()
function.
<?php add_action('admin_menu', 'add_comments_menu'); function add_comments_menu(){ add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Custom Post Types Menu?
To add a menu item under your custom post type item.
<?php add_action('admin_menu', 'add_custom_post_menu'); function add_custom_post_menu(){ add_submenu_page( 'edit.php?post_type=your_post_type', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Because custom post types aren’t default WordPress menus there is no inbuilt function to use to add sub-menus.
How To Add Your Menu Under Appearance Menu?
To add a menu item under the appearance item.
<?php add_action('admin_menu', 'add_appearance_menu'); function add_appearance_menu(){ add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the function add_theme_page()
to add the theme settings page.
<?php add_action('admin_menu', 'add_appearance_menu'); function add_appearance_menu(){ add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Plugins Menu?
To add a menu item under the plugins item.
<?php add_action('admin_menu', 'add_plugins_menu'); function add_plugins_menu(){ add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the add_plugins_page()
function.
<?php add_action('admin_menu', 'add_plugins_menu'); function add_plugins_menu(){ add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Users Menu?
To add a menu item under the users item.
<?php add_action('admin_menu', 'add_users_menu'); function add_users_menu(){ add_submenu_page( 'users.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the function add_users_page()
.
<?php add_action('admin_menu', 'add_users_menu'); function add_users_menu(){ add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
How To Add Your Menu Under Tools Menu?
To add a menu item under the tools item.
<?php add_action('admin_menu', 'add_tools_menu'); function add_tools_menu(){ add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you can use the add_management_page()
function.
<?php add_action('admin_menu', 'add_tools_menu'); function add_tools_menu(){ add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function ); } ?>
How To Add Your Menu Under Settings Menu?
To add a menu item under the settings item.
<?php add_action('admin_menu', 'add_settings_menu'); function add_settings_menu(){ add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function); } ?>
Or you use the add_options_page()
function.
<?php add_action('admin_menu', 'add_settings_menu'); function add_settings_menu(){ add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options'); } ?>
Last Words:
This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.
Be the first to write a comment.