Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to prevent non-admins from accessing “/wp-admin” dashboard?


  • pantone
    Participant

    @pantone

    Is there a code I can place inside functions.php that will prevent non-admins from accessing the “/wp-admin” dashboard? Ideally, this code will redirect non-admins to the homepage.

Viewing 2 replies - 1 through 2 (of 2 total)

  • modemlooper
    Moderator

    @modemlooper

    BuddyPress users should not be able to get to WP-admin as they are only subscribers


    9087877
    Inactive

    Add this code snippet to your child themes functions.php and it will do what you need.

    <?php //Removes Access To Dashboard By Non-Admins Per Shawn
    function baw_no_admin_access()
    {
    if( !current_user_can( 'administrator' ) ) {
    wp_redirect( home_url() );
    die();
    }
    }
    add_action( 'admin_init', 'baw_no_admin_access', 1 );
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to prevent non-admins from accessing “/wp-admin” dashboard?’ is closed to new replies.
Skip to toolbar