Each time I register I end up in the wp-login page (back-end):

enter image description here

Is there any way of redirecting the users who register to a page template (front-end)?

  • check the available plugins for code samples – kaiser Jun 10 '11 at 14:45
  • @kaiser what kind of plugins? – janoChen Jun 10 '11 at 15:08
  • Redirect Plugins - Your clients will like it. – kaiser Jun 10 '11 at 16:09
up vote 11 down vote accepted

You can use the filter registration_redirect to pass back your own URL, for example;

function wpse_19692_registration_redirect() {
    return home_url( '/my-page' );
}

add_filter( 'registration_redirect', 'wpse_19692_registration_redirect' );

Drop it in your functions.php or a plugin :)

  • Thanks for the answer but I'm still being redirected to the wp-login back-end :( (I'm working on localhost LAMP, but I don't think that's the reason). – janoChen Jun 10 '11 at 16:09
  • Are you sure the theme with the code is active? And which version of WP are you running? It worked fine for me (tested just now, 3.1.3). – TheDeadMedic Jun 10 '11 at 16:21
  • 1
    OK it worked after I deactivated bbPress I guess there is a conflict with the plugin. Thanks! – janoChen Jun 10 '11 at 16:26
  • @TheDeadMedic I have a similar question but i'm registering from a page with a custom template that includes a registration form. The redirect isn't working it's taking me back to the main registration page with message to check my email for the password. Can you take a look at my question please. wordpress.stackexchange.com/questions/130560/… – Anagio Jan 20 '14 at 22:11

This is what i use

<form action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
<input type="text" name="user_login" value="Username" id="user_login" class="input" />
<input type="text" name="user_email" value="E-Mail" id="user_email" class="input"  />
<?php do_action('register_form'); ?>
<input type="submit" value="Register" id="register" />
<input type="hidden" name="redirect_to" value="/success"/>
<p class="statement">A password will be e-mailed to you.</p>
</form>

If like me, you use a plugin like ProfilePress to power/create your WordPress registration form, the following code will automatically log in and redirect registered users to a welcome page.

add_action( 'pp_after_registration', 'pp_redirect_after_registration', 10, 3 );

function pp_redirect_after_registration( $form_id, $user_data, $user_id ) {

    wp_set_auth_cookie( $user_id );
    wp_set_current_user( $user_id );

    $custom_page_url = 'http://example.com/welcome/';

    wp_redirect( $custom_page_url );
    exit;
}

Note: I use the free plugin (https://wordpress.org/support/plugin/ppress) version and the above code work both in free and the PRO version.

I have developed a plugin for this issue. Also given below is the raw code for a redirect without any plugin.

/**
 * Redirect users to custom URL based on their role after login
 **/
function wp_woo_custom_redirect( $redirect, $user ) {

    // Get the first of all the roles assigned to the user
    $role = $user->roles[0];
    $dashboard = admin_url();
    $myaccount = get_permalink( wc_get_page_id( 'my-account' ) );

    if( $role == 'administrator' ) {

        //Redirect administrators to the dashboard
        $admin_redirect = get_option('admin_redirect');
        $redirect = $admin_redirect;
    } elseif ( $role == 'shop-manager' ) {

        //Redirect shop managers to the dashboard
        $shop_manager_redirect = get_option('shop_manager_redirect');
        $redirect = $shop_manager_redirect;
    } elseif ( $role == 'customer' || $role == 'subscriber' ) {

        //Redirect customers and subscribers to the "My Account" page
        $customer_redirect = get_option('customer_redirect');
        $redirect = $customer_redirect;
    } else {

        //Redirect any other role to the previous visited page or, if not available, to the home
        $redirect = wp_get_referer() ? wp_get_referer() : home_url();
    }
    return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'wp_woo_custom_redirect', 10, 2 );

If you feel comfortable working with plugin or without code? You can download and install my plugin "WP WooCommerce Redirect"

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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