When I try to create a main menu, with this line
add_menu_page("page title","menu name",10,"test-slug");
WordPress loads just fine and displays the new menu, but when I try to add a submenu,
add_menu_page("page title","menu name",10,"test-slug");
add_submenu_page("test-slug","sub title","sub menu",10,"test-sub-slug");
only an empty page is displayed, right after half a second. Seems like a php-error, but I can’t see the error. Does anyone see what I am doing wrong?
2
Answers
Problem solved. add_submenu_page() obviously must be called using a hook. Hence, this way it works and will not cause Wordpress to crash:
Try the code below in your functions.php file. It should work correctly.