Either a WordPress plugin or a code written by the previous programmer is conflicting with WordPress admin bar causing it to always be visible. If you are an admin, no error is raised, however if you are a visitor you'd see a console error.
What I want to do, is that whenever you see this error in the console, hide the admin bar. Because normally visitors should not see the admin bar, I'm trying a quick hack.
The error is the following
Uncaught TypeError: Cannot read property 'addEventListener' of null
This is what I tried, I learned this hack from here after some research:
jQuery(document).ready(function($) {
var original = window.console
window.console = {
error: function() {
//Gets text from error message.
errorText = arguments['0'];
if (errorText.includes('TypeError')) {
jQuery("#wpadminbar").css("display", "none");
}
original.error.apply(original, arguments)
}
}
});
I know I'm mixing JavaScript and jQuery -- I'll fix that later, but I just wanted to check if this hack would work. It's not working, not even executing the function, is there any other way to check for console errors?