WordPress wp_loginout() Function

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

Definition

In WordPress, wp_loginout() prints one link that changes with the visitor. Guests see "Log in", and logged-in users see "Log out".

It is the quickest way to add a login link to a menu, header, or footer.

Syntax

Call it where you want the link to appear.

WordPress
<?php wp_loginout(); ?>
CallWhat it does
wp_loginout()Prints Log in or Log out.
wp_loginout( home_url() )Goes to the home page after the action.
wp_loginout( '', false )Returns the link instead of printing.

The link text is "Log in" or "Log out" and can be translated.

Full declaration
WordPress
wp_loginout( string $redirect = '', bool $display = true ): void|string

Parameters

ParameterDescription
$redirectstring. The page to open after logging in or out. Default is empty.
$displaybool. true (default) prints the link. false returns it.

Return Value

Return ValueDescription
voidWhen $display is true, the link is printed.
stringWhen $display is false, the link HTML is returned.

WordPress Examples

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

Example 1 — Add the link to the footer

Print the right link for each visitor.

WordPress
<p><?php wp_loginout(); ?></p>

How It Works

  1. The function checks if the visitor is logged in.
  2. Guests get a login link.
  3. Members get a logout link with a security nonce.

Example 2 — Go to the home page afterwards

Send the visitor to the home page after the action.

WordPress
<?php wp_loginout( home_url() ); ?>

How It Works

  1. The first argument is the address to open next.
  2. It is added as redirect_to.
  3. Both links send the visitor home.

Example 3 — Return the link

Wrap the link in a list item.

WordPress
<?php
$link = wp_loginout( '', false );
echo '<li class="menu-item">' . $link . '</li>';

How It Works

  1. $display is false, so the link is returned.
  2. We store it in $link.
  3. Then we print it inside our own list item.

Frequently Asked Questions

It prints a Log in link for guests and a Log out link for logged-in users.
No. The function checks the login state for you.
Pass false as the second argument: wp_loginout( '', false ).
Use wp_login_url() and wp_logout_url() with is_user_logged_in() to build the links yourself.

Next: wp_logout_url()

Get the address that logs the current user out, with an optional redirect.

wp_logout_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.

8 people found this page helpful