WordPress wp_login_form() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, wp_login_form() outputs a login form that you can place on any page, such as a sidebar or a custom "My account" page.

After a successful login, the visitor goes to the address you set with redirect. If you do not set it, they return to the current page.

Syntax

Show the form only to visitors who are not logged in.

WordPress
<?php
if ( ! is_user_logged_in() ) {
  wp_login_form();
}
CallWhat it does
wp_login_form()Prints the login form.
wp_login_form( array( 'redirect' => home_url() ) )Sends the user to the home page after login.
wp_login_form( array( 'echo' => false ) )Returns the form as a string.

Use is_user_logged_in() to hide the form from logged-in users.

Full declaration
WordPress
wp_login_form( array $args = [] ): void|string

Parameters

ParameterDescription
$argsarray. Options include echo, redirect, form_id, label_username, label_password, label_remember, label_log_in, remember, and value_username. Default is an empty array.

Return Value

Return ValueDescription
voidWhen echo is true (default), the form is printed.
stringWhen echo is false, the form HTML is returned.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Show a login form

Put a form in a sidebar for guests.

WordPress
<?php if ( ! is_user_logged_in() ) : ?>
  <h3>Member login</h3>
  <?php wp_login_form(); ?>
<?php endif; ?>

How It Works

  1. is_user_logged_in() is false for guests.
  2. The form posts to wp-login.php.
  3. WordPress handles the login for you.

Example 2 — Redirect after login

Send members to their account page.

WordPress
<?php
wp_login_form( array(
  'redirect' => home_url( '/my-account/' ),
) );

How It Works

  1. redirect sets the page after a good login.
  2. home_url() builds the full address.
  3. A hidden field carries the address to wp-login.php.

Example 3 — Change the labels

Use friendlier text.

WordPress
<?php
wp_login_form( array(
  'label_username' => 'Your email',
  'label_password' => 'Your password',
  'label_log_in'   => 'Sign in',
  'remember'       => false,
) );

How It Works

  1. The label args change the text.
  2. remember is false, so the checkbox is hidden.
  3. Everything else stays the same.

Frequently Asked Questions

It prints a ready-made login form that you can place on any page of your site.
To the address in the redirect argument. If it is empty, they return to the current page.
Wrap it in if ( ! is_user_logged_in() ).
Pass array( 'echo' => false ) and echo the result yourself.

Next: wp_login_url()

Get the address of the login page, with an optional redirect.

wp_login_url() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful