admin_menu

Home » Hooks » admin_menu

The admin_menu hook is an essential hook in WordPress that allows developers to add or remove items from the WordPress admin menu. This hook is used to customize the WordPress dashboard by adding new menus or submenus to the left navigation bar.

When WordPress loads the admin menu, it triggers the admin_menu hook, which allows developers to add their custom functions to this hook. By doing so, developers can register new menu items or submenus inside the WordPress dashboard. Additionally, this hook can be used to remove unnecessary menus and submenus, which can help to declutter the WordPress dashboard and create a more streamlined user experience.

Here’s an example usage code of the admin_menu hook in WordPress:

function my_custom_menu() {
    add_menu_page(
        'My Custom Menu', // Page title
        'Custom Menu', // Menu title
        'manage_options', // Capability
        'my-custom-menu', // Menu slug
        'my_custom_menu_page', // Callback function
        'dashicons-admin-site' // Icon URL
    );
}

add_action('admin_menu', 'my_custom_menu');

In the above example, we’ve created a custom menu called "My Custom Menu" with a custom icon using the add_menu_page function. We’ve added the custom menu item to the WordPress dashboard using the admin_menu hook. When the admin_menu hook is triggered, WordPress will execute our custom function, my_custom_menu, which registers our custom menu item within the WordPress dashboard.

Overall, the admin_menu hook is a powerful tool for WordPress developers who want to customize the WordPress dashboard by adding or removing menus and submenus.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.