wordpress add_submenu_page adds broken link

WordPress is doing exactly what you’re telling it to do. Refer to the Codex entry for add_submenu_page(). The functions arguments are like so:

<?php 
add_submenu_page( 
    $parent_slug, 
    $page_title, 
    $menu_title, 
    $capability, 
    $menu_slug, 
    $function 
);
?>

So, you’re assigning the same string to $parent_slug and $menu_slug. For obvious reasons, these two need to be different.

  • $parent_slug is the slug of the parent menu page. You assign that as basename( __FILE__ ) in your add_menu_page() call.

  • $menu_slug is the slug of the sub-menu page. Note what the Codex says:

    If you want to NOT duplicate the parent menu item, you need to set the name of the $menu_slug exactly the same as the parent slug.

While this statement is written confusingly, I think it’s saying that by setting $parent_slug and $menu_slug the same, you’re replacing the main-parent sub-menu entry with this page – and it sounds like that’s not what you want to do.