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

  • Sorry but I don't understand what you are trying to do. – Laxmana Apr 23 '17 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 Apr 23 '17 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 Apr 23 '17 at 11:38
  • @Laxmana in first answer say docs of wp_login_form but i said don't work and don't redirect – Alireza Apr 23 '17 at 11:44
  • Use home_url() instead of site_url() – Laxmana Apr 23 '17 at 11:44
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.

  • thanks but don't work. user will be redirected to /wp-admin/profile.php! – Alireza Apr 23 '17 at 11:34
  • @Laxmana use 'home_url()' but don't work – Alireza Apr 23 '17 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. – Mervan Agency Apr 23 '17 at 11:57

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.