add menu item to the dashboard menu of wordpress

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 ); ?>

Read More

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:add_custom_menu_item

Related posts

Leave a Reply

2 comments

  1. 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 the admin_menu action.

    Here’s an example working code with WP 3.4.2

    function register_custom_menu_page() {
        add_menu_page('custom menu title', 'custom menu', 'add_users', 'custompage', '_custom_menu_page', null, 6); 
    }
    add_action('admin_menu', 'register_custom_menu_page');
    
    function _custom_menu_page(){
       echo "Admin Page Test";  
    }
    
  2. This is a perfect answer.

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
        register_post_type( 'acme_product',
            array(
                'labels' => array(
                    'name' => __( 'Products' ),
                    'singular_name' => __( 'Product' )
                ),
            'public' => true,
            'has_archive' => true,
            )
        );
    }