5

Is it possible to add custom links as submenu on menu that already exist in wp-admin? Like for example, under appearance section like this: enter image description here

1 Answer 1

12

For the custom link into the admin menu, you need to pick up a top-level menu item by its slug and register the function using the admin_menu action hook.

Here is the list of Main Admin Menu slugs.

index.php => Dashboard
edit.php => Posts
upload.php => Media
link-manager.php => Links
edit.php?post_type=page => Pages
edit-comments.php => Comments
themes.php => Appearance
plugins.php => Plugins
users.php => Users
tools.php => Tools
options-general.php => Settings

List of all admin menus and submenus names, keys, and slugs. Image Source

enter image description here

If you want to use the external link then the code is:

add_action('admin_menu', 'add_custom_link_into_appearance_menu');
function add_custom_link_into_appearance_menu() {
    global $submenu;
    $permalink = 'http://www.customlink.com';
    $submenu['themes.php'][] = array( 'Custom Link', 'manage_options', $permalink );
}

If you want to render the custom link page using WordPress Administrations Menus functions then the code is:

 add_action('admin_menu', 'add_custom_link_into_appearance_menu');
 function add_custom_link_into_appearance_menu() {
    add_theme_page('Custom Link Page Title', 'Custom Link Menu Title', 'manage_options', 'custom-link-unique-identifier', 'render_custom_link_page');
 }

 function render_custom_link_page() {
    echo 'Custom Link Page';
 }
4
  • Thanks a lot for such a detailed reply! It really helps a lot. Thank you! Commented May 9, 2017 at 2:29
  • @archangel17 Great.. I'm glad this helped! Commented May 9, 2017 at 2:47
  • Method 1 worked well for my custom post type. Thx ! Commented Jul 25, 2018 at 15:52
  • Thank you @SyedFakharAbbas. The first option worked for me as well. I wanted to add my option page tabs as submenu items. The only issue I'm having is adding the current class to the submenu links. Do you know how I can do this?
    – Michael
    Commented Jan 25, 2021 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.