How to remove duplicate link from add_menu_page

There is a workaround to hide this automatically created submenu. In the past I’ve used it quite often, but lately I have returned to leaving it as is (or renaming it, as m0r7if3r suggested).

Also note, that aside your main question, you have switched the positions of the menu_slug and function arguments in add_menu_page, see the codex for reference.

This is how it is done anyhow:

/* Add top level menu */
add_menu_page(
    'MyTheme', 
    'MyTheme Menu Label',
    'edit_themes', 
    'theme_admin',        // menu slug
    'functions.php',        // function
    get_bloginfo('template_directory') .'/img/favicon.png',
    31
);

/* remove duplicate menu hack */
add_submenu_page(
    'theme_admin',        // parent slug, same as above menu slug
    '',        // empty page title
    '',        // empty menu title
    'edit_themes',        // same capability as above
    'theme_admin',        // same menu slug as parent slug
    'functions.php',        // same function as above
}

This isn’t too clean, but afaik the only way to hide the duplicate submenu.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)