Redirecting users to referrer page after logging in using custom login form

The key part is right here– 'redirect' => admin_url(), in your first block of code. Whatever you set that to is where you will redirect. I don’t see a reason for the second block if you are redirecting everyone.

There is no function that I can find for “this page” so you probably want $_SERVER['REQUEST_URI']

$args = array(
    'redirect' => esc_url($_SERVER['REQUEST_URI']), 
    'form_id' => 'loginform-custom',
    'label_username' => __( 'Username' ),
    'label_password' => __( 'Password' ),
    'label_remember' => __( 'Remember Me' ),
    'label_log_in' => __( 'Log In' ),
    'remember' => true
);
wp_login_form( $args );

Be careful with $_SERVER vars: http://markjaquith.wordpress.com/2009/09/21/php-server-vars-not-safe-in-forms-or-links/

Leave a Comment