Using WordPress ‘adminmenu’ PHP action

The adminmenu WordPress PHP action fires after the admin menu has been output.

Usage

add_action('adminmenu', 'my_custom_function');

function my_custom_function() {
  // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: adminmenu

Examples

add_action('adminmenu', 'add_custom_admin_link');

function add_custom_admin_link() {
  // Add a custom link to the admin menu
  echo '<li><a href="https://example.com" target="_blank">Visit Example</a></li>';
}

Hide a specific menu item for non-admin users

add_action('adminmenu', 'hide_menu_item_for_non_admins');

function hide_menu_item_for_non_admins() {
  if (!current_user_can('manage_options')) {
    // Hide the Appearance menu item for non-admin users
    echo '<style>#menu-appearance { display: none; }</style>';
  }
}

Add a custom separator in the admin menu

add_action('adminmenu', 'add_custom_separator');

function add_custom_separator() {
  // Add a custom separator to the admin menu
  echo '<li class="wp-menu-separator"></li>';
}

Add a custom message to the admin menu

add_action('adminmenu', 'add_custom_message');

function add_custom_message() {
  // Add a custom message to the admin menu
  echo '<li><span class="update-plugins count-1"><span class="plugin-count">Important Message</span></span></li>';
}

Change the color of a specific menu item

add_action('adminmenu', 'change_menu_item_color');

function change_menu_item_color() {
  // Change the color of the Posts menu item
  echo '<style>#menu-posts a { color: red; }</style>';
}