WordPress wp_login_url() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
URL helper

Definition

In WordPress, wp_login_url() returns the URL of the login page, which is usually https://example.com/wp-login.php.

You can add a $redirect address so the visitor lands on that page after logging in. Use it to build your own "Log in" link.

Syntax

It returns a string, so echo it inside an escape function.

WordPress
<?php
echo esc_url( wp_login_url() );
CallWhat it does
wp_login_url()The login page address.
wp_login_url( get_permalink() )Log in, then return to this post.
wp_login_url( '', true )Ask the user to log in again.

Always wrap the result in esc_url() when you print it.

Full declaration
WordPress
wp_login_url( string $redirect = '', bool $force_reauth = false ): string

Parameters

ParameterDescription
$redirectstring. The address to open after login. Default is empty.
$force_reauthbool. If true, the user must log in again, even if already logged in. Default is false.

Return Value

Return ValueDescription
stringThe login URL, with redirect_to and reauth added when needed.

WordPress Examples

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

Example 2 — Return to the current post

Send the visitor back here after login.

WordPress
<?php if ( ! is_user_logged_in() ) : ?>
  <a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>">
    Log in to comment
  </a>
<?php endif; ?>

How It Works

  1. get_permalink() is the address of this post.
  2. It is added to the URL as redirect_to.
  3. After login, the user returns to the post.

Example 3 — Force a new login

Ask for the password again before a sensitive page.

WordPress
<?php
$url = wp_login_url( home_url( '/billing/' ), true );
echo esc_url( $url );

How It Works

  1. The second argument is true.
  2. WordPress adds reauth=1 to the URL.
  3. The user must sign in again, then lands on the billing page.

Frequently Asked Questions

It returns the URL of the login page as a string, usually ending in wp-login.php.
Pass the address as the first argument, for example wp_login_url( get_permalink() ).
No. It returns only the URL. Create the link tag yourself or use wp_loginout().
When true, the user must log in again, even if they are already logged in.

Next: wp_loginout()

Print a Log in or Log out link, depending on the visitor.

wp_loginout() 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.

7 people found this page helpful