do_action( 'admin_menu', string $context )

Fires before the administration menu loads in the admin.


Parameters

$context string
Empty context.

Top ↑

More Information

  • This action is used to add extra submenus and menu options to the admin panel’s menu structure. It runs after the basic admin panel menu structure is in place.
  • This action mustn’t be placed in an admin_init action function because the admin_init action is called after admin_menu.

Top ↑

Source

File: wp-admin/includes/menu.php. View all references

do_action( 'admin_menu', '' );

Top ↑

Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Aurovrata Venet

    If you want to change a menu label, you can hook this action and change the global $menu, $submenu values,

    add_action( 'admin_menu', 'change_media_label' );
    function change_media_label(){
      global $menu, $submenu;
      debug_msg($menu);
      $menu[10][0] = 'Photos/Videos';
      $submenu['upload.php'][5][0] = 'All Photos/Videos';
      $submenu['upload.php'][10][0] = 'Upload new';
    }
  2. Skip to note 2 content
    Contributed by Steven Lin

    Example migrated from Codex:

    The example comes from the wpautop-control plugin, in which the code is used to add an options page to the “Settings” menu.

    add_action('admin_menu', 'wpautop_control_menu');
    
    function wpautop_control_menu() {
      add_submenu_page('options-general.php', 'wpautop-control', 'wpautop control', 'manage_options', 'wpautop-control-menu', 'wpautop_control_options');
    }
  3. Skip to note 3 content
    Contributed by Milad

    This snippet add admin menu and submenu HTML content

    //call the 'add_menu_page' function with 'admin_menu' action hook
    	add_action( 'admin_menu', array( $this, 'wpdocs_add_menu_page' ), 99 );
    
        /**
         * Add page to admin menu
         */
        public function wpdocs_add_menu_page() {
            add_menu_page(
                esc_html__( 'WooCommerce B2B Sales Agents', 'woocommerce-b2b-sales-agents' ),
                esc_html__( 'WooCommerce B2B Sales Agents', 'woocommerce-b2b-sales-agents'),
                'manage_woocommerce',
                'wcb2bsa-commissions',
                null,
                'dashicons-businessman',
                55.5
            );
            add_submenu_page(
                'wcb2bsa-commissions',
                esc_html__( 'Commissions', 'woocommerce-b2b-sales-agents' ),
                esc_html__( 'Commissions', 'woocommerce-b2b-sales-agents' ),
                'manage_woocommerce',
                'wcb2bsa-commissions',
                array( $this, 'wpdocs_add_menu_page_callback' )
            );
        }
    
        /**
         * Add page to admin menu callback
         */
        public function wpdocs_add_menu_page_callback() {
            include WCB2BSA_ABSPATH . 'includes/views/html-admin--page-commissions.php';
        }
  4. Skip to note 4 content
    Contributed by Chigozie Orunta

    Let’s say you’re building a plugin and you need to register an overview or dashboard menu option for your plugin page, you can do it like so:

    // Define constants
    define( 'PLUGIN_SLUG', 'your-plugin' );
    define( 'PLUGIN_ROLE', 'manage_options' );
    define( 'PLUGIN_DOMAIN', 'your-plugin-text-domain' );
    
    add_action( 'admin_menu', 'register_your_plugin_menu', 9 );
    
    function register_your_plugin_menu() {
    	add_menu_page(
    		__( 'Your Plugin', PLUGIN_DOMAIN ),
    		'Your Plugin',
    		PLUGIN_ROLE,
    		PLUGIN_SLUG,
    		false,
    		'dashicons-admin-generic',
    		''
    	);
    
    	add_submenu_page(
    		PLUGIN_SLUG,
    		'Your Plugin',
    		'Dashboard',
    		PLUGIN_ROLE,
    		PLUGIN_SLUG,
    		'your_plugin_dashboard_callback',
    	);
    }

You must log in before being able to contribute a note or feedback.