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&#91;'tools.php'&#93;&#91;5&#93;);
	if(count($submenu&#91;'tools.php'&#93;) == 0) {
		remove_menu_page('tools.php');
	}
}
?>

Submit a Comment

Your email address will not be published.