2

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

7

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_appearnace_menu');
function add_custom_link_into_appearnace_menu() {
    global $submenu;
    $permalink = 'http://www.cusomtlink.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_appearnace_menu');
 function add_custom_link_into_appearnace_menu() {
    add_theme_page('Custom Link Pgae Title', 'Custom Link Menu Title', 'manage_options', 'custom-link-unique-identifier', 'render_custom_link_page');
 }

 function render_custom_link_page() {
    echo 'Custom Link Page';
 }
  • Thanks a lot for such a detailed reply! It really helps a lot. Thank you! – Archangel17 May 9 '17 at 2:29
  • @archangel17 Great.. I'm glad this helped! – Syed Fakhar Abbas May 9 '17 at 2:47
  • Method 1 worked well for my custom post type. Thx ! – AyexeM Jul 25 '18 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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