Wordpress - remove_menu_page doesn't work on custom plugin menus
Place this below temporary code in your functions.php
or any where that can be executed.
add_action( 'admin_init', 'the_dramatist_debug_admin_menu' );
function the_dramatist_debug_admin_menu() {
echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>';
}
Then search for the plugin-slug
. In which array you find it copy the [2]
value and put it in remove_menu_page('the [2] value')
and hook it to admin_init
like below-
add_action('admin_init', '');
function the_dramatist_remove_menu(){
remove_menu_page( 'the [2] value' );
});
And it will be working. And after it is working remove the temporary code block.
On the other hand, you can inspect the plugin code which menu page you wanna remove and in their add_menu_page()
function take the fourth parameter of the add_menu_page()
function and put it inside remove_menu_page('fourth parameter')
. It will work as well. The code will look like below-
add_action('admin_init', '');
function the_dramatist_remove_menu(){
remove_menu_page( 'fourth parameter of add_menu_page()' );
});
Thanks to the answer that the_dramatist posted, it was a matter of just hooking to the admin_init
tag. The slugs for those plugin pages can be retrieved by the debug script that the_dramatist provided, or you can simply look at that query value after admin.php?page=plugin-slug
:
add_action( 'admin_init', 'wpse_243070_hide_menu' );
function wpse_243070_hide_menu() {
remove_menu_page( 'index.php' ); // Dashboard
remove_menu_page( 'tools.php' ); // Tools
remove_menu_page( 'plugin-slug' ); // Some plugin
remove_menu_page( 'another_slug' ); // Another plugin
}