Home / Admin / Restrict Dashboard Access
Duplicate Snippet

Embed Snippet on Your Site

Restrict Dashboard Access

Restrict dashboard access to users with editable capacity. And, redirect all others to site's homepage.

Code Preview
php
<?php
function disable_dashboard_access() {
    $file = basename( $_SERVER['PHP_SELF'] );
    if ( is_user_logged_in() && is_admin() && ! current_user_can( 'edit_posts' ) && $file != 'admin-ajax.php' ) {
        wp_redirect( home_url() );
        exit;
    }
}
add_action( 'init', 'disable_dashboard_access' );   

Comments

Add a Comment