I am trying the following syntax to add menu-item on dashboard:
<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>
But, I am confused where to add this code.
Whether to add it in my theme’s functions.php or my plugin’s functions.php ?
Or any other way to add custom menu-item on the dashboard of the wordpress logged in as admin ?
I want to add custom menu item like the following image:
What you see in the screenshot is the screen of a Custom Post Type. In the documentation you will find an example code on how to add such a screen.
About where to place the code – it depends. Do you want to be able to use this Custom Post Type in other themes, or you will only need it in this theme?
If you want to use it in other themes as well, put the code in your plugin’s code.
If you want to use it only in this theme, put it in your theme’s
functions.php
.And in case you still want to add a custom menu page, here you will find examples on what is the proper way to use this function. What you should note, is that the call to
add_menu_page()
should be done inside a function that is run on theadmin_menu
action.Here’s an example working code with WP 3.4.2
This is a perfect answer.