I'm creating a plugin for WordPress with dynamic sub-menu's fetched from the server. Putting the dynamic loading of sub-menu's into the menu_setup() hook function would slow down other WordPress operations and should only execute once user clicks/selects the top level menu item, but the add_submenu_page(...) function are not executing/showing up in menu_init() hook.

Here is my example code:

add_action( 'admin_menu', 'menu_setup');

function menu_setup()

    // Creates a top-level Menu item.
    add_menu_page( 'Chur', 'Chur', 'manage_options', 'chur-plugin', 'menu_init');

function menu_init(){

    // Dynamic submenu 
    add_submenu_page( 'chur-plugin', 'Chur 1', 'Chur 1', 'manage_options', 'chur_1', 'menu_page' );
    add_submenu_page( 'chur-plugin', 'Chur 2', 'Chur 2', 'manage_options', 'chur_2', 'menu_page' );
    add_submenu_page( 'chur-plugin', 'Chur 3', 'Chur 3', 'manage_options', 'chur_3', 'menu_page' );


function menu_page(){ //Show page content };

Is there a way around this? or a limitation to WordPress?

  • Is there a way around a problem caused by putting something that does something you haven't explained into a function? Can you try to expand upon this question please? – s_ha_dum Jul 26 '15 at 14:18
  • I have updated my answer to be more clear. – Kivylius Jul 26 '15 at 16:20

Your Answer

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

Browse other questions tagged or ask your own question.