WordPress Restrict Dashboard to Administrators Only

WordPress Restrict Dashboard to Administrators Only
130 Views

Restrict Dashboard to Administrators Only

<?php
add_action( 'init', 'cxc_restrict_admin_access_call_back' );
function cxc_restrict_admin_access_call_back() {
    if ( is_admin() && ! current_user_can( 'administrator' ) && ! wp_doing_ajax() ) {
        wp_redirect( home_url() );
        exit;
    }
}
?>

Was this article helpful?
YesNo

Leave a comment

Your email address will not be published.