Title: wp_login_form
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_login_form( array $args = array() ): void|string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#wp--skip-link--target)

Provides a simple login form for use anywhere within WordPress.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#description)󠁿

The login form HTML is echoed by default. Pass a false value for `$echo` to return
it instead.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#parameters)󠁿

 `$args`arrayoptional

Array of options to control the form output.

 * `echo` bool
 * Whether to display the login form or return the form HTML code.
    Default true(
   echo).
 * `redirect` string
 * URL to redirect to. Must be absolute, as in "<a href="https://example.com/mypage/"
   >https://example.com/mypage/</a>".
    Default is to redirect back to the request
   URI.
 * `form_id` string
 * ID attribute value for the form. Default `'loginform'`.
 * `label_username` string
 * Label for the username or email address field. Default ‘Username or Email Address’.
 * `label_password` string
 * Label for the password field. Default `'Password'`.
 * `label_remember` string
 * Label for the remember field. Default ‘Remember Me’.
 * `label_log_in` string
 * Label for the submit button. Default ‘Log In’.
 * `id_username` string
 * ID attribute value for the username field. Default `'user_login'`.
 * `id_password` string
 * ID attribute value for the password field. Default `'user_pass'`.
 * `id_remember` string
 * ID attribute value for the remember field. Default `'rememberme'`.
 * `id_submit` string
 * ID attribute value for the submit button. Default `'wp-submit'`.
 * `remember` bool
 * Whether to display the "rememberme" checkbox in the form.
 * `value_username` string
 * Default value for the username field.
 * `value_remember` bool
 * Whether the "Remember Me" checkbox should be checked by default.
    Default false(
   unchecked).
 * `required_username` bool
 * Whether the username field has the `'required'` attribute.
    Default false.
 * `required_password` bool
 * Whether the password field has the `'required'` attribute.
    Default false.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#return)󠁿

 void|string Void if `'echo'` argument is true, login form HTML if `'echo'` is false.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#source)󠁿

    ```php
    function wp_login_form( $args = array() ) {
    	$defaults = array(
    		'echo'              => true,
    		// Default 'redirect' value takes the user back to the request URI.
    		'redirect'          => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
    		'form_id'           => 'loginform',
    		'label_username'    => __( 'Username or Email Address' ),
    		'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'    => '',
    		// Set 'value_remember' to true to default the "Remember me" checkbox to checked.
    		'value_remember'    => false,
    		// Set 'required_username' to true to add the required attribute to username field.
    		'required_username' => false,
    		// Set 'required_password' to true to add the required attribute to password field.
    		'required_password' => false,
    	);

    	/**
    	 * Filters the default login form output arguments.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @see wp_login_form()
    	 *
    	 * @param array $defaults An array of default login form arguments.
    	 */
    	$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );

    	/**
    	 * Filters content to display at the top of the login form.
    	 *
    	 * The filter evaluates just following the opening form tag element.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param string $content Content to display. Default empty.
    	 * @param array  $args    Array of login form arguments.
    	 */
    	$login_form_top = apply_filters( 'login_form_top', '', $args );

    	/**
    	 * Filters content to display in the middle of the login form.
    	 *
    	 * The filter evaluates just following the location where the 'login-password'
    	 * field is displayed.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param string $content Content to display. Default empty.
    	 * @param array  $args    Array of login form arguments.
    	 */
    	$login_form_middle = apply_filters( 'login_form_middle', '', $args );

    	/**
    	 * Filters content to display at the bottom of the login form.
    	 *
    	 * The filter evaluates just preceding the closing form tag element.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param string $content Content to display. Default empty.
    	 * @param array  $args    Array of login form arguments.
    	 */
    	$login_form_bottom = apply_filters( 'login_form_bottom', '', $args );

    	$direction_style = is_rtl() ? ' style="direction: ltr;"' : '';

    	$form =
    		sprintf(
    			'<form name="%1$s" id="%1$s" action="%2$s" method="post">',
    			esc_attr( $args['form_id'] ),
    			esc_url( site_url( 'wp-login.php', 'login_post' ) )
    		) .
    		$login_form_top .
    		sprintf(
    			'<p class="login-username">
    				<label for="%1$s">%2$s</label>
    				<input type="text" name="log" id="%1$s" autocomplete="username" class="input" value="%3$s" size="20"%4$s%5$s />
    			</p>',
    			esc_attr( $args['id_username'] ),
    			esc_html( $args['label_username'] ),
    			esc_attr( $args['value_username'] ),
    			( $args['required_username'] ? ' required="required"' : '' ),
    			$direction_style
    		) .
    		sprintf(
    			'<p class="login-password">
    				<label for="%1$s">%2$s</label>
    				<input type="password" name="pwd" id="%1$s" autocomplete="current-password" spellcheck="false" class="input" value="" size="20"%3$s%4$s />
    			</p>',
    			esc_attr( $args['id_password'] ),
    			esc_html( $args['label_password'] ),
    			( $args['required_password'] ? ' required="required"' : '' ),
    			$direction_style
    		) .
    		$login_form_middle .
    		( $args['remember'] ?
    			sprintf(
    				'<p class="login-remember"><label><input name="rememberme" type="checkbox" id="%1$s" value="forever"%2$s /> %3$s</label></p>',
    				esc_attr( $args['id_remember'] ),
    				( $args['value_remember'] ? ' checked="checked"' : '' ),
    				esc_html( $args['label_remember'] )
    			) : ''
    		) .
    		sprintf(
    			'<p class="login-submit">
    				<input type="submit" name="wp-submit" id="%1$s" class="button button-primary" value="%2$s" />
    				<input type="hidden" name="redirect_to" value="%3$s" />
    			</p>',
    			esc_attr( $args['id_submit'] ),
    			esc_attr( $args['label_log_in'] ),
    			esc_url( $args['redirect'] )
    		) .
    		$login_form_bottom .
    		'</form>';

    	if ( $args['echo'] ) {
    		echo $form;
    	} else {
    		return $form;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/general-template.php#L726)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L726-L854)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#hooks)󠁿

 [apply_filters( ‘login_form_bottom’, string $content, array $args )](https://developer.wordpress.org/reference/hooks/login_form_bottom/)

Filters content to display at the bottom of the login form.

 [apply_filters( ‘login_form_defaults’, array $defaults )](https://developer.wordpress.org/reference/hooks/login_form_defaults/)

Filters the default login form output arguments.

 [apply_filters( ‘login_form_middle’, string $content, array $args )](https://developer.wordpress.org/reference/hooks/login_form_middle/)

Filters content to display in the middle of the login form.

 [apply_filters( ‘login_form_top’, string $content, array $args )](https://developer.wordpress.org/reference/hooks/login_form_top/)

Filters content to display at the top of the login form.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#related)󠁿

| Uses | Description | 
| [is_ssl()](https://developer.wordpress.org/reference/functions/is_ssl/)`wp-includes/load.php` |

Determines if SSL is used.

  | 
| [is_rtl()](https://developer.wordpress.org/reference/functions/is_rtl/)`wp-includes/l10n.php` |

Determines whether the current locale is right-to-left (RTL).

  | 
| [site_url()](https://developer.wordpress.org/reference/functions/site_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 6 more](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Added `required_username` and `required_password` arguments. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#comment-content-503)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_login_form/#comment-503)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%23comment-503)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%23comment-503)
 4.  This example displays a login form.
 5.      ```php
         <?php wp_login_form(); ?>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%3Freplytocom%3D503%23feedback-editor-503)
 7.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#comment-content-5476)
 8.    [benjamintoth](https://profiles.wordpress.org/benjamintoth/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_login_form/#comment-5476)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%23comment-5476)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%23comment-5476)
 10. I have found this function is often broken by the admin_email_check update for
     WP 5.3 resulting in a silent login failure. If you run into silent login failures
     try disabling the admin email check.
 11. // Disable administration email verification
      add_filter( ‘admin_email_check_interval’,‘
     __return_false’ );
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%3Freplytocom%3D5476%23feedback-editor-5476)
 13.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_login_form/?output_format=md#comment-content-4072)
 14.   [Shahar A](https://profiles.wordpress.org/shago_go/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/wp_login_form/#comment-4072)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%23comment-4072)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%23comment-4072)
 16. This example displays a login form as shortcode ([wpdocs_log_me]).
 17.     ```php
         function wpdocs_log_me_shortcode_fn() {
     
           $args = array(
             'echo'            => true,
             'redirect'        => get_permalink( get_the_ID() ),
             'remember'        => true,
             'value_remember'  => true,
           );
     
           return wp_login_form( $args );
     
         }
         add_shortcode( 'wpdocs_log_me', 'wpdocs_log_me_shortcode_fn' );
         ```
     
 18.  * Since you are returning it from inside a shortcode callback, you want to return
        a string instead of displaying it. Thus, it should be `'echo' => false` in 
        my opinion.
      * [SkillsUp](https://profiles.wordpress.org/skillsup/) [6 years ago](https://developer.wordpress.org/reference/functions/wp_login_form/#comment-4697)
 19.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F%3Freplytocom%3D4072%23feedback-editor-4072)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_login_form%2F)
before being able to contribute a note or feedback.