Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As the title of this post says i need to create a registration form to let readers register to my site and access to special contents not visible to everybody.

Is there some plugin that handles this features? I've tryed some, but after login they redirect me on wordpress admin back-end.

I do not want to allow people access to website admin page.

Any suggestion?

share|improve this question
    
Have you already tried searching redirect on the site? There're plenty example of this. In short: exit( wp_redirect( home_url( '/' ) ) );... One example is my answer here. –  kaiser Oct 8 '12 at 9:05
add comment

1 Answer

Paste this into your functions.php file and edit according to comments.

add_filter('login_redirect', 'redirect_user', 10);

function redirect_user(){

    global $user;

    //where you want to redirect users too
    $redirect = home_url() . '/where-do-we-go-from-here/';

   /*
    *  each role listed in this array will be redirect to above URL
    *  if you only have one user role to redirect then simply remove
    *  the others.
    */

    $role = array( 

        'subscriber',
        'another_role',
        'etc'

    );

    if ( in_array( $user->roles[0], array( 'administrator') ) ) {

        //admin will go to the dashboard
        return admin_url();

    } elseif ( in_array( $user->roles[0], $role ) ) {

        return $redirect;

    } 

}

I should add that the following,

$redirect = home_url() . '/where-do-we-go-from-here/';
//returns http://www.example.com/where-do-we-go-from-here/

Can also be written as,

$redirect = home_url( '/where-do-we-go-from-here/' );
//returns http://www.example.com/where-do-we-go-from-here/

...where by the function home_url accepts the path as one of its arguments/parameters.

share|improve this answer
add comment

Your Answer

 
discard

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.