WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'm looking a way to avoid regular users go to profile and dashboard page. Have this little code to work with profile page:

function lockdown_profile()
    global $current_user;
    return !current_user_can( 'manage_options' ) ? wp_redirect("/profile") : true;
add_action('show_user_profile', "lockdown_profile");

And works, but i need to do the same for dashboard page, any ideas?

share|improve this question
up vote 1 down vote accepted

show_user_profile is the wrong hook to use. You should redirect before anything gets sent to the browser (eg. before headers are sent).

Fortunately there are actions that happen much earlier: load-{$pagename} is the one you want. So you can hook into load-index.php and load-profile.php to throw people back to the front end.

add_action( 'load-profile.php', 'wpse35742_maybe_redirect' );
add_action( 'load-index.php', 'wpse35742_maybe_redirect' );
function wpse35742_maybe_redirect()
    if( current_user_can( 'manage_options' ) ) return;
    wp_redirect( home_url( '/profile' ), 302 );

All that said, you would be better off adding a new role that has even more limited capabilities than the typical subscribers: don't let them view the dashboard or their profiles (the read capability).

share|improve this answer
This work great, thank you. – greenbandit Dec 7 '11 at 6:21

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.