Limit Dashboard access in your WordPress site

If you run a site where user can sign-up but you don’t want them to access wp-admin/dashboard area , then following simple code snippet will do the trick you want. Limiting Dashboard access in your WordPress is as simple as that.

add_action( 'init', 'limit_dashboard_access' );
function  limit_dashboard_access() {
    if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
        wp_redirect( home_url() );
        exit;
    }
}

Add this code in your theme’s functions.php file. Now only you ( or users with admin role ) can access Dashboard area. Users with other roles will be redirected to site Homepage. And if you want you can change that redirect url by replacing home_url() in the code with your custom URL.


Post Tags


About The Author


Leave a Reply

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