How to hide tools option in menu bar if no submenu is available

How can I automatically remove tools menu in WordPress admin dashboard if no option are available (for example for a user with the editor role).

Insert this code on your functions.php file or plugin:

<?php
/*
* Hide tools option in menu bar if no submenu is available
*
*/
add_action('admin_init', 'wpster_remove_tools_admin_menu');
function wpster_remove_tools_admin_menu() {
	global $submenu;
	unset($submenu['tools.php'][5]);
	if(count($submenu['tools.php']) == 0) {
		remove_menu_page('tools.php');
	}
}
?>

Submit a Comment

Your email address will not be published. Required fields are marked *