How to hide WordPress error messages?


How to hide WordPress error messages  like  “You do not have sufficient permissions to access this page” and show 404 error page for all non administrator’s request like e.g mydomain.com/wp-admin/plugin.php and all such requests. And they should be redirected to 404 error page.

Here are two solution for your problem, You are requested to take backup of your plugin or theme before implementing this method of your live system.

Copy this code inside you functions.php file or your plugin file depending upon where do you want to redirect your visitor from  showing these error message(s).

Hide WordPress error messages and Redirect visitor on 404 Page

If you want to 404 page of your WordPress theme instead of normal WordPress error message then the code below will do this job very effectively.

add_filter('wp_die_handler','custom_404_die_handler');
function custom_404_die_handler() {
    global $wp;
    $wp->handle_404();
    load_template(get_404_template());
    die();
}

but if you want to redirect your reader  somewhere, then you could do something like this, but that’s not exactly a “404”, as such. In this code reader will be redirected to the home page of the website/blog.

add_filter('wp_die_handler','custom_404_die_handler');
function custom_404_die_handler() {
    wp_safe_redirect( get_home_url() );
    die();
}

Source : Source : Originally shared by Samuel Wood (Otto) on Wp Answer




Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>