WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want all my users (contributors and authors too) but the admin to be redirected to the homepage if they try to view mysite.com/wp-admin/. Contributors and Authors must be able to add and edit posts as usual, along with others they've to be forced to be redirected... I've already removed the link to the dashboard... I've also tried some plugins but the one that gets closer (Remove Dashboard Access) redirects to main page but prevents the contributors and authors from adding, editing and deleting posts. Thanks!

share|improve this question

I been using this code for a while I think it was originaly on a plugin called wp block admin but this works. You just have tho change the required compatibility so that it does what you need, look at this

$required_capability = 'edit_others_posts';
$redirect_to = '';
function no_admin_init() {      
    // We need the config vars inside the function
    global $required_capability, $redirect_to;      
    // Is this the admin interface?
    if (
        // Look for the presence of /wp-admin/ in the url
        stripos($_SERVER['REQUEST_URI'],'/wp-admin/') !== false
        // Allow calls to async-upload.php
        stripos($_SERVER['REQUEST_URI'],'async-upload.php') == false
        // Allow calls to admin-ajax.php
        stripos($_SERVER['REQUEST_URI'],'admin-ajax.php') == false
    ) {         
        // Does the current user fail the required capability level?
        if (!current_user_can($required_capability)) {              
            if ($redirect_to == '') { $redirect_to = get_option('home'); }              
            // Send a temporary redirect
// Add the action with maximum priority
share|improve this answer
It's not the way it's meant to be done, but +1 for considering the admin-ajax.php file. – kaiser Mar 13 '13 at 11:00

There're only two things you need to check:

  • If the user is in the admin interface
  • If he got the capability or not

As long as we're using the template_redirect hook we don't have to check the login/register/password pages as the redirect will happen invisible to the user.

Here's the idea wrapped up as a little (mu-)plugin.

 * Plugin Name: (#90535) Redirect Non-Admin users to the "Home"-page.
 * Description: Checks if we're in the admin UI and if the user has the admin only 'manage_options' capability
 * Version:     2013.03.12
 * Author:      Franz Josef Kaiser
add_action( 'template_redirect', 'wpse90535_admin_denied' );
function wpse90535_admin_denied()
    and ! current_user_can( 'manage_options' )
        and exit( wp_redirect( home_url(), 302 ) );
share|improve this answer
up vote 0 down vote accepted

Unfortunately none of the above codes worked for me as they just redirected non admin to homepage even if I wanted authors and contributors to be able to add/edit and delete their posts... I've ended removing the boxes in the dashboard and I solved (partially) my issue.

I added this in functions.php

function disable_default_dashboard_widgets() {

    remove_meta_box('dashboard_right_now', 'dashboard', 'core');
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'core');
    remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
    remove_meta_box('dashboard_plugins', 'dashboard', 'core');

    remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
    remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core');
    remove_meta_box('dashboard_primary', 'dashboard', 'core');
    remove_meta_box('dashboard_secondary', 'dashboard', 'core');
add_action('admin_menu', 'disable_default_dashboard_widgets');
share|improve this answer
Oh, seems like we both misread your question... Take our answers, modify them and then try again. Or make your question more clear with A) where the login/registration/password should redirect too and B) what exact page the user should get access too and to which one not. – kaiser Mar 13 '13 at 11:02

I know this is still a old question but you can have a look.

function redirect_non_admin_user(){
    if ( !defined( 'DOING_AJAX' ) && !current_user_can('administrator') ){
        wp_redirect( site_url() );  exit;

add_action( 'admin_init', 'redirect_non_admin_user' );

This checking is very IMPORTANT "!defined( 'DOING_AJAX' )" when you use admin ajax call in frontend.

share|improve this answer

One addition: ALWAYS check to see if there is a logged in user otherwise you will prevent secured items from displaying on login screen:

function redirect_non_admin_user(){
    if ( is_user_logged_in() ) {
        if ( !defined( 'DOING_AJAX' ) && !current_user_can('administrator') ){
            wp_redirect( site_url() );  exit;
add_action( 'admin_init', 'redirect_non_admin_user' );

Thank you so much for offering this solution :-)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.