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 Answers 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.


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>

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 );

Add Below in your function.php

function admin_default_page() {
  $site1=$site."/* slug- name for page*/";
  return $site1;
add_filter('login_redirect', 'admin_default_page');
  • Always include a bit of an explanation with your posted answer - that way users can get an understanding of what the solution is, why it's a good solution, what the different functionality is doing, etc. May 18, 2020 at 14:23

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 and acknowledge you have read our privacy policy.

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