Sunday, May 31, 2015

How to create custom login page on frontend side in wordpress?

1) On index.php below get_header();

<?php
            if(!is_user_logged_in())
{
    ?>
    <script>window.location.href = '<?php echo home_url()."/login";?>';</script>
    <?php
    //wp_redirect(home_url()."/login");
}   
?>

2)Create file name "custom-login.php" and paste the following

<?php
/*
Template Name: Custom Login
*/
get_header();   
    if(isset($_POST["wp-submit"]))
    {
        $args = array(
        'echo' => true,
        'redirect' => site_url( $_SERVER['REQUEST_URI'] ),
        'form_id' => 'loginform',
        '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 );
        $args = array('redirect' => get_permalink( get_page( $page_id_of_member_area ) ) );
    }
   
    if(is_user_logged_in())
    {
    ?>
        <script>window.location.href = '<?php echo home_url();?>';</script>
    <?php
    }
    else
    {
        wp_login_form( $args );
    }
get_footer();
?>

3) Create backend page name "Login", Select template "Custom Login" and publish page.

No comments:

Post a Comment

Please mention your comments.......