When using the add_submenu_page
to create a new submenu in WooCommerce, I get “Cannot modify header information – headers already sent”. The add_submenu_page
is as follows:
public function slp_add_menu_item() { add_submenu_page( 'woocommerce', 'Shipping Locations', 'Shipping Locations', 'manage_options', 'slp_add_states', array( $this->slp_settings_page() ), ); }
Changing that to the following removes the “Cannot modify header information – headers already sent” errors but fails to render callback function properly:
public function slp_add_menu_item() { add_submenu_page( 'woocommerce', 'Shipping Locations', 'Shipping Locations', 'manage_options', 'slp_add_states', array( $this, 'slp_settings_page' ), ); }
The slp_settings_page
callback function, in turn, renders an instance of WP_List_Table
(It’s not a taxonomy despite the appearances in the screenshots above). The add_submenu_page
is added through the admin_menu
hook without any priorities.
Any ideas on what’s happening here? I can’t seem to wrap my head around it 🙁
Advertisement
Answer
The first code block is wrong. According to the documentation the last parameter should be a callable. The first block directly executes the function and stores the result in an array (with the result being null
, by the way). So, passing that as a callable won’t work.
Why the second block isn’t working exactly I don’t know. Perhaps the code block gets executed at the wrong time, perhaps something else is amiss.