Example 1 — Add the link to the footer
Print the right link for each visitor.
<p><?php wp_loginout(); ?></p> How It Works
- The function checks if the visitor is logged in.
- Guests get a login link.
- Members get a logout link with a security nonce.

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.
Call it where you want the link to appear.
<?php wp_loginout(); ?> | Call | What 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.
wp_loginout( string $redirect = '', bool $display = true ): void|string | Parameter | Description |
|---|---|
$redirect | string. The page to open after logging in or out. Default is empty. |
$display | bool. true (default) prints the link. false returns it. |
| Return Value | Description |
|---|---|
| void | When $display is true, the link is printed. |
| string | When $display is false, the link HTML is returned. |
Three short theme examples. Each one shows the code and what it prints.
Print the right link for each visitor.
<p><?php wp_loginout(); ?></p> Send the visitor to the home page after the action.
<?php wp_loginout( home_url() ); ?> redirect_to.Wrap the link in a list item.
<?php
$link = wp_loginout( '', false );
echo '<li class="menu-item">' . $link . '</li>'; $display is false, so the link is returned.$link.Get the address that logs the current user out, with an optional redirect.
8 people found this page helpful