Title: Front-End Login using PHP
Last modified: August 21, 2016

---

# Front-End Login using PHP

 *  Resolved [nickioa](https://wordpress.org/support/users/nickguitarify/)
 * (@nickguitarify)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/)
 * Hello all,
 * I’m trying my best to add a login box to the front-end of my site. Using plugins
   hasn’t worked well so far aesthetically.
 * My preferred method so far has been to install ExecPHP and paste code into the
   widget in the footer, which works ok.
 * Further to what I’ve done so far, I’d like to:
    - Add “Register | Forgot your password?” links for non-logged in users
    - Add a link to account management for logged in users
    - Remove the “Remember Me” box entirely, as it doesn’t sit well with the theme
 * Would anyone be kind enough to help me out? My current code is below.
 *     ```
       <?php
       if ( ! is_user_logged_in() ) { // Display WordPress login form:
           $args = array(
               'redirect' => admin_url(),
               'form_id' => 'loginform-custom',
               'label_username' => __( 'Username' ),
               'label_password' => __( 'Password' ),
               'label_remember' => __( 'Remember Me' ),
               'label_log_in' => __( 'Log In' ),
               'remember' => true
               );
           wp_login_form( $args );
       } else { // If logged in:
           wp_loginout( home_url() ); // Display "Log Out" link.
           echo " | ";
           wp_register('', ''); // Display "Site Admin" link.
       }
       ?>
       ```
   
 * Thanks,
 * Nick 🙂

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231618)
 * What do you mean by account management? Are you referring to the dashboard?
 * The other things are covered with the following code:
 *     ```
       <?php
       if ( ! is_user_logged_in() ) { // Display WordPress login form:
           $args = array(
               'redirect' => admin_url(),
               'form_id' => 'loginform-custom',
               'label_username' => __( 'Username' ),
               'label_password' => __( 'Password' ),
               'label_log_in' => __( 'Log In' ),
               'remember' => true
               );
           wp_login_form( $args );
           echo wp_lostpassword_url( $redirect );
           echo wp_registration_url();
       } else { // If logged in:
           wp_loginout( home_url() ); // Display "Log Out" link.
           echo " | ";
           wp_register('', ''); // Display "Site Admin" link.
       }
       ?>
       ```
   
 *  Thread Starter [nickioa](https://wordpress.org/support/users/nickguitarify/)
 * (@nickguitarify)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231676)
 * Thanks for responding! The Dashboard, that’s correct.
 * I’ve entered the new code into the widget, which results in this (Chrome):
 * [http://i.imgur.com/CzT4e5L.jpg](http://i.imgur.com/CzT4e5L.jpg)
 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231726)
 * Just to be clear, you want the admin link to show if they are logged in correct?
   If not they would just be redirected to another login screen which would be pointless
   unless I’m missing something.
 * Try this for displaying lost password and registration links:
 *     ```
       <?php
       if ( ! is_user_logged_in() ) { // Display WordPress login form:
           $args = array(
               'redirect' => admin_url(),
               'form_id' => 'loginform-custom',
               'label_username' => __( 'Username' ),
               'label_password' => __( 'Password' ),
               'label_log_in' => __( 'Log In' ),
               'remember' => true
               );
           wp_login_form( $args );
           wp_lostpassword_url( $redirect );
           wp_registration_url();
       } else { // If logged in:
           wp_loginout( home_url() ); // Display "Log Out" link.
           echo " | ";
           wp_register('', ''); // Display "Site Admin" link.
       }
       ?>
       ```
   
 *  Thread Starter [nickioa](https://wordpress.org/support/users/nickguitarify/)
 * (@nickguitarify)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231732)
 * That’s correct, yes.
 * I’ve copied in the latest code, and now nothing displays for the
 *     ```
       wp_login_form( $args );
           wp_lostpassword_url( $redirect );
           wp_registration_url();
       ```
   
 * part (whereas before we had plain text as the picture in my last post illustrates).
 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231751)
 * Sorry, try this. Of course you may need to style this with css:
 *     ```
       <?php
       if ( ! is_user_logged_in() ) { // Display WordPress login form:
           $args = array(
               'redirect' => admin_url(),
               'form_id' => 'loginform-custom',
               'label_username' => __( 'Username' ),
               'label_password' => __( 'Password' ),
               'label_log_in' => __( 'Log In' ),
               'remember' => true
               );
           wp_login_form( $args );
           echo '<a href="' . wp_lostpassword_url( $redirect ) . '">Lost Password?</a>';
           echo '<a href="' . wp_registration_url() . '">Register</a>';
       } else { // If logged in:
           wp_loginout( home_url() ); // Display "Log Out" link.
           echo " | ";
           wp_register('', ''); // Display "Site Admin" link.
       }
       ?>
       ```
   
 *  Thread Starter [nickioa](https://wordpress.org/support/users/nickguitarify/)
 * (@nickguitarify)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231755)
 * Thank you so much graphical_force, that has cracked it! Now I’ll spend some time
   figuring out how to make it appear like this:
 * Register | Lost Password?
 * I’m trying
 *     ```
       echo '<a href="' . wp_registration_url() . '">Register</a>';
           echo " | ";
           echo '<a href="' . wp_lostpassword_url( $redirect ) . '">Lost Password?</a>';
       ```
   
 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231757)
 * There are a few ways to do that. The way you are doing it there should work as
   well.
 *  Thread Starter [nickioa](https://wordpress.org/support/users/nickguitarify/)
 * (@nickguitarify)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231765)
 * Would you be kind enough to share the other methods with me? Mine didn’t end 
   up displaying the | at all unfortunately.
 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231804)
 * Try this:
 *     ```
       <?php
       if ( ! is_user_logged_in() ) { // Display WordPress login form:
           $args = array(
               'redirect' => admin_url(),
               'form_id' => 'loginform-custom',
               'label_username' => __( 'Username' ),
               'label_password' => __( 'Password' ),
               'label_log_in' => __( 'Log In' ),
               'remember' => true
               );
           wp_login_form( $args );
           echo '<a href="' . wp_lostpassword_url( $redirect ) . '">Lost Password?</a> | <a href="' . wp_registration_url() . '">Register</a>';
       } else { // If logged in:
           wp_loginout( home_url() ); // Display "Log Out" link.
           echo " | ";
           wp_register('', ''); // Display "Site Admin" link.
       }
       ?>
       ```
   
 *  Thread Starter [nickioa](https://wordpress.org/support/users/nickguitarify/)
 * (@nickguitarify)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231825)
 * Perfect, thank you so much graphical_force. Your help is greatly appreciated!
   🙂
 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231826)
 * No problem. 🙂

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Front-End Login using PHP’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 2 participants
 * Last reply from: [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/front-end-login-using-php/#post-4231826)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
