2

I just want to redirect the users to their current page after logged in my wordpress website. I have used the following but it won`t work for me since it is in page that created from the admin side.

<?php echo wp_login_url(get_permalink()); ?>
5

You can use the login_redirect filter to do this. One of the parameters is $request, which

is the URL the user is coming from

function wpse125952_redirect_to_request( $redirect_to, $request, $user ){
    // instead of using $redirect_to we're redirecting back to $request
    return $request;
}
add_filter('login_redirect', 'wpse125952_redirect_to_request', 10, 3);

The filter could additionally easily be used for distinguishing redirect destinations by user roles. Take a look at the documentation for a deeper insight into that.

1

Try wp_redirect() http://codex.wordpress.org/Function_Reference/wp_redirect Maybe the_permalink() will help you depending on where you're logging in from.

Alternatively is this what you're looking for?

<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
0

What do you mean by user's current page?

Anyway, have you tried using the built-in wp_login_form() function?

You may want to use it this way:

$args = array(
    'echo' => true,
    // This could be your User's Current Page?
    'redirect' => site_url( $_SERVER['REQUEST_URI'] ),
    'form_id' => 'user-login-form',
    'label_username' => __( 'Username' ),
    'label_password' => __( 'Password' ),
    'label_remember' => __( 'Remember Me' ),
    'label_log_in' => __( 'Log In' ),
    'id_username' => 'user_login',
    'id_password' => 'user_pass',
    'id_remember' => 'rememberme',
    'id_submit' => 'wp-submit',
    'remember' => true,
    'value_username' => NULL,
    'value_remember' => false );

wp_login_form( $args );
-1

Problem solved. I have installed a Wordpress plugin to execute Php code on pages.Then

<?php echo wp_login_url(get_permalink()); ?>

works well on wordpress pages. http://wordpress.org/plugins/insert-php/

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.