X

Hide Toolbar When There’s an Error

Just put this code in your functions.php file or functionality plugin. When you have a PHP error this code will hide the admin toolbar. Letting you see the error.

Code Snippet:

function wp_error($errno, $errstr, $errfile, $errline){
	$errorType = array (
		 E_ERROR 			=> 'ERROR',
		 E_CORE_ERROR     		=> 'CORE ERROR',
		 E_COMPILE_ERROR  		=> 'COMPILE ERROR',
		 E_USER_ERROR     		=> 'USER ERROR',
		 E_RECOVERABLE_ERROR            => 'RECOVERABLE ERROR',
		 E_WARNING        		=> 'WARNING',
		 E_CORE_WARNING   		=> 'CORE WARNING',
		 E_COMPILE_WARNING 		=> 'COMPILE WARNING',
		 E_USER_WARNING   		=> 'USER WARNING',
		 E_NOTICE         		=> 'NOTICE',
		 E_USER_NOTICE    		=> 'USER NOTICE',
		 E_DEPRECATED			=> 'DEPRECATED',
		 E_USER_DEPRECATED		=> 'USER_DEPRECATED',
		 E_PARSE          		=> 'PARSING ERROR'
	);
	if (array_key_exists($errno, $errorType)) {
		$errname = $errorType[$errno];
	} else {
		$errname = 'UNKNOWN ERROR';
	}
	echo $errname. ' Error: [' . $errno . '] ' . $errstr . $errfile . ' on line ' . $errline;
	remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
}
if(is_admin()){
	set_error_handler('wp_error', E_ERROR ^ E_CORE_ERROR ^ E_COMPILE_ERROR ^ E_USER_ERROR ^ E_RECOVERABLE_ERROR ^ E_WARNING ^ E_CORE_WARNING ^ E_COMPILE_WARNING ^ E_USER_WARNING ^ E_NOTICE ^ E_USER_NOTICE ^ E_DEPRECATED ^ E_USER_DEPRECATED ^ E_PARSE );
}

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!