0

I have added a login form to a page template using wp_login_form(). This page template is used for a welcome/login page for an online seminar. When the user logs in I want them to be redirected to the online seminar page. Here is the code I used:

if (is_user_logged_in()) {               
            echo '<div class="logout"> <p>Hello!<div class="logout_user"> You are logged in and can proceed to the <a href="http://example.com/seminar">Online Seminar</a>.</div></p><br /><p><a id="wp-submit" class="logout" href="', wp_logout_url(), '" title="Logout">Logout</a></p></div>';
        } else { 
          wp_login_form($args);

                  $args = array(
                            'echo'           => true,
                            'redirect'       => site_url('/seminar'),
                            'label_log_in'   => __( 'Log in' ),
                            'form_id'        => 'seminar-login',
                            'label_username' => __( 'Username' ),
                            'label_password' => __( 'Password' ),
                            'label_remember' => __( 'Remember Me' ),
                            'id_username'    => 'user_login',
                            'id_password'    => 'user_pass',
                            'id_submit'      => 'wp-submit',
                            'remember'       => true,
                            'value_username' => NULL,
                            'value_remember' => true
                            ); 
        }

When I set it up yesterday it seemed to be redirecting just fine, but today it just stays on the welcome/login page. I read that this is the default action, so it seems to be ignoring the redirect. I tried using an absolute url:

'redirect' => 'http://example.com/seminar',

But, that didn't work either.

I've tried to think what might be affecting this (ie. plugin conflicts) and two things might be relevant. I use AIOWPSecurity to rename the login page and access to the seminar itself is controlled by the Groups plugin. But, that doesn't explain why it was working when I set it up yesterday, but not working now.

Does anyone have any ideas why the redirect doesn't work?

Thank You!

2
  • 3
    Define the $args array BEFORE the call to wp_login_form().
    – shanebp
    Jun 25 '15 at 1:10
  • What @shanebp said and you were already using an absolute URL as the redirect value. site_url( '/seminar/ ' ) will produce an absolute URL. Jun 25 '15 at 6:58
2

Your code contains a mistake in passing arguments to the wp_login_form() function. If you define the arguments after function then the function will be called with the default values, so your arguments will not have any effect. The correct code is below:

if (is_user_logged_in()) {               
    echo '<div class="logout"> <p>Hello!<div class="logout_user"> You are logged in and can proceed to the <a href="http://example.com/seminar">Online Seminar</a>.</div></p><br /><p><a id="wp-submit" class="logout" href="', wp_logout_url(), '" title="Logout">Logout</a></p></div>';
} else { 
    $args = array(
        'echo'           => true,
        'redirect'       => 'http://example.com/seminar',
        'label_log_in'   => __( 'Log in' ),
        'form_id'        => 'seminar-login',
        'label_username' => __( 'Username' ),
        'label_password' => __( 'Password' ),
        'label_remember' => __( 'Remember Me' ),
        'id_username'    => 'user_login',
        'id_password'    => 'user_pass',
        'id_submit'      => 'wp-submit',
        'remember'       => true,
        'value_username' => NULL,
        'value_remember' => true
    );
    wp_login_form($args); 
}
2
  • 1
    Please add a proper explanation to what your code does and how it works. And stop using other accounts to vote your answers up. Jun 25 '15 at 7:40
  • So simple. I can't believe I spent so long looking for the answer. Thank you! Jun 25 '15 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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