0


I search my question but all users that said paste custom code in functions.php
I have two Page Templates for login with this code:

<?php 
$args = array(
    'echo'           => true,
    'remember'       => true,
    'redirect'       => 'mysite.com',
    'form_id'        => 'loginform',
    'id_username'    => 'user_login',
    'id_password'    => 'user_pass',
    'id_remember'    => 'rememberme',
    'id_submit'      => 'wp-submit',
    'label_username' => __( 'Username' ),
    'label_password' => __( 'Password' ),
    'label_remember' => __( 'Remember Me' ),
    'label_log_in'   => __( 'Log In' ),
    'value_username' => '',
    'value_remember' => false
);
wp_login_form( $args ); ?>

but when users click on button redirect to /wp-admin.
I need two login page with two different redirect

5
  • Sorry but I don't understand what you are trying to do.
    – Laxmana
    Commented Apr 23, 2017 at 11:00
  • @Laxmana i need a login form in my page when user login from this page redirect to mysite.com not mysite.com/wp-admin
    – Alireza
    Commented Apr 23, 2017 at 11:30
  • If you read at the docs of wp_login_form it says that the redirect url must be absolute meaning http://example.org
    – Laxmana
    Commented Apr 23, 2017 at 11:38
  • @Laxmana in first answer say docs of wp_login_form but i said don't work and don't redirect
    – Alireza
    Commented Apr 23, 2017 at 11:44
  • Use home_url() instead of site_url()
    – Laxmana
    Commented Apr 23, 2017 at 11:44

1 Answer 1

1

I have tried your code with little modification in 2 Page Templates and it seems to be working. The only change I did was in the redirect parameter. Below is the updated code with the redirect parameter. You need to provide absolute path in redirect parameter. Please check the function reference of wp_login_form on following link. https://codex.wordpress.org/Function_Reference/wp_login_form

$args = array(
    'echo'           => true,
    'remember'       => true,
    'redirect'       => site_url( '/page-slug'),
    'form_id'        => 'loginform',
    'id_username'    => 'user_login',
    'id_password'    => 'user_pass',
    'id_remember'    => 'rememberme',
    'id_submit'      => 'wp-submit',
    'label_username' => __( 'Username' ),
    'label_password' => __( 'Password' ),
    'label_remember' => __( 'Remember Me' ),
    'label_log_in'   => __( 'Log In' ),
    'value_username' => '',
    'value_remember' => false
);
wp_login_form( $args );

In the above code, user will be redirected to http://domain_name/page-slug page after login.

3
  • thanks but don't work. user will be redirected to /wp-admin/profile.php!
    – Alireza
    Commented Apr 23, 2017 at 11:34
  • @Laxmana use 'home_url()' but don't work
    – Alireza
    Commented Apr 23, 2017 at 11:49
  • @Alireza - It might be possible that there is some filter like login_redirect or hook like wp_login is used in your setup which is causing the issue. Commented Apr 23, 2017 at 11:57

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.