Add menu in wordpress admin

Wordpress Tutorials, WrodPress Programmatically

Add menu in wordpress admin

Add menu in wordpress admin

WordPress is providing the best admin dashboard from where to we can manage all the things and it’s very easy to add  menu in WordPress admin for custom functionality. Sometimes we also need that same type of menu and pages also need child menu for that menu. so for that WordPress has already default functions and activities that will allow you to create own menu with page content so we can create our custom WordPress admin dashboard setting page.

add_action(‘admin_menu’, ‘menu_page_function’);

Above function is an action that will add menu action name is admin_menu and another parameter is the menu page function in that function code will write for add menu in the admin dashboard.

Below are the function is used for add menu page.

add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = ”, string $icon_url = ”, int $position = null )

$page_title: That is the title of the page that contains with parent menu in the admin dashboard.

$menu_title: That parameter is to define the menu title that will display on the admin dashboard left sidebar.

$capability: The capability required for this menu to be displayed to the user.

$menu_slug: That is the slug of that menu page for the unique link so we can access that page with our custom page slug.

$function: That function contains the page code and content for that menu in that function we can create all the setting in a page.

$icon_url: If we need to set an image icon for that menu then also we can set that it’s option not required.

$position: We can also set the position of that menu display on the left sidebar as per priority we can give position with number default is null.

Below is the full example of creating menu page and submenu on the admin dashboard.

add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
    add_menu_page('My Page Title', 'My Parent Menu', 'manage_options', 'custom-menu-slug', 'parent_menu_page' );
    add_submenu_page('custom-menu-slug', 'Submenu Page Title', 'My Submenu 1', 'manage_options', 'sub-menu-slug1' , 'sub_menu_page1' );
    add_submenu_page('custom-menu-slug', 'Submenu Page Title', 'My Submenu 2', 'manage_options', 'sub-menu-slug2' , 'sub_menu_page2' );

function parent_menu_page()
	echo '<h1>Hi This Is Parent Menu Page</h1>';
	echo '<p>That is first admin menu page created BY: Helpyouforever</p>';

function sub_menu_page1()
	echo '<h1>Hi This Is Submenu Menu Page 1</h1>';
	echo '<p>That is first admin submenu page created BY: Helpyouforever</p>';

function sub_menu_page2()
	echo '<h1>Hi This Is Submenu Menu Page 2</h1>';
	echo '<p>That is first admin submenu page created BY: Helpyouforever</p>';

Below is the image that will display that menu.

Add menu in wordpress admin 1

In above example, we can easily see that in my_menu_pages() function we have written three lines of code in that first line will add admin parent menu and another two line will add a submenu for that parent menu.

If we don’t need a page for all that page then not need to create a function for that if we will not provide function then the menu will display only but page will not display for that particular menu.

In most of that cases, we need a menu on admin dashboard where we need to create our custom functionality. In lots of themes we showing the menu like theme options panel menu that is all about admin menu there always used that menu functions and on menu function, they have created all the option with a beautiful design so using that menu page we can also create our custom page.



6 thoughts on “Add menu in wordpress admin

  1. I and also my pals ended up studying the great guides from the blog and then then I had a horrible suspicion I never thanked the web site owner for them. Those boys happened to be as a result thrilled to read through them and have in effect in fact been having fun with those things. I appreciate you for indeed being so thoughtful and also for going for certain good things most people are really wanting to learn about. Our honest regret for not expressing appreciation to you earlier.

  2. Hmm it seems like your website ate my first comment (it was super long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog. I too am an aspiring blog writer but I’m still new to everything. Do you have any tips and hints for beginner blog writers? I’d certainly appreciate it.

  3. Do you have a spam problem on this blog; I also am a blogger, and I was wanting to know your situation; we have developed some nice procedures and we are looking to swap methods with other folks, please shoot me an e-mail if interested.

Leave a Reply