Prevent access to wp-admin redirect subscribers to home page

Adding this code to your functions.php will redirect subscribers away from wp-admin to the home page.

if ( is_user_logged_in() && is_admin() ) {
    global $current_user;
    $user_info = get_userdata($current_user->ID);
	if ( $user_info->wp_user_level == 0 )
		header( 'Location: '.get_bloginfo('home').'/wp-login.php?redirect='.get_bloginfo('home').'/wp-admin/' );

Comments  Leave a Reply

  1. if you want it to redirect your homepage and not the login page us this:

    header( ‘Location: ‘.get_bloginfo(‘home’).’/?redirect=’.get_bloginfo(‘home’).’/wp-admin/’ );

    instead of

    header( ‘Location: ‘.get_bloginfo(‘home’).’/wp-login.php?redirect=’.get_bloginfo(‘home’).’/wp-admin/’ );

  2. Thank you very much, it works but redirects me to another login.php panel, can’t it be home?

  3. Glenton Samuels June 21, 2012 at 11:37 am

    Doesn’t work for me.

  4. Wow thanks honey 🙂

    1.  No problem enjoy the snippet.

  5. Jason K. Seegmiller March 4, 2011 at 6:29 pm

    Does it matter where we add it?

    1. Just into the functions.php the location within that file does not matter.

  6. Tweets that mention WPSNIPP – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com November 21, 2010 at 2:43 pm

    […] This post was mentioned on Twitter by wp_freak, WPSNIPP. WPSNIPP said: #wordpress Prevent access to wp-admin http://bit.ly/9CyZeF #blog please RT 🙂 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!