WordPress wp_logout_url() Function

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

Definition

In WordPress, wp_logout_url() returns the URL that logs the current user out. The address includes a security nonce, so it only works for the user who is logged in right now.

Pass a $redirect address to choose the page the user sees after logging out.

Syntax

It returns a string, so wrap it in esc_url() when you print it.

WordPress
<?php
echo esc_url( wp_logout_url( home_url() ) );
CallWhat it does
wp_logout_url()The logout address.
wp_logout_url( home_url() )Log out, then go to the home page.
wp_logout_url( get_permalink() )Log out, then return to this page.

It builds only the URL. You write the link tag.

Full declaration
WordPress
wp_logout_url( string $redirect = '' ): string

Parameters

ParameterDescription
$redirectstring. The page to open after logging out. Default is empty.

Return Value

Return ValueDescription
stringThe logout URL with a nonce, and redirect_to when you pass one.

WordPress Examples

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

Example 2 — Go home after logout

Send the user to the home page.

WordPress
<a href="<?php echo esc_url( wp_logout_url( home_url() ) ); ?>">Sign out</a>

How It Works

  1. The first argument is the next page.
  2. It is added as redirect_to.
  3. After logout the user lands on the home page.

Example 3 — Add the link to a menu

Add Log out at the end of a nav menu.

WordPress
<?php
add_filter( 'wp_nav_menu_items', function ( $items, $args ) {
  if ( is_user_logged_in() && 'primary' === $args->theme_location ) {
    $items .= '<li><a href="' . esc_url( wp_logout_url( home_url() ) ) . '">Log out</a></li>';
  }
  return $items;
}, 10, 2 );

How It Works

  1. The filter changes the menu items.
  2. We check the menu location and the login state.
  3. A logout link is added to the end of the list.

Frequently Asked Questions

It returns a secure URL that logs the current user out.
The nonce is a security check. It stops other sites from logging a user out without permission.
Pass the address as the first argument, for example wp_logout_url( home_url() ).
No. It returns only the URL. Use wp_loginout() if you want a ready-made link.

Next: wp_lostpassword_url()

Get the address of the "Lost your password?" page.

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

9 people found this page helpful