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

---

# wp_loginout( string $redirect = '', bool $display = true ): void|string

## In this article

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

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

Displays the Log In/Out link.

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

Displays a link, which allows users to navigate to the Log In page to log in or 
log out depending on whether they are currently logged in.

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

 `$redirect`stringoptional

Optional path to redirect to on login/logout.

Default:`''`

`$display`booloptional

Default to echo and not return the link.

Default:`true`

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

 void|string Void if `$display` argument is true, log in/out link if `$display` 
is false.

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

    ```php
    function wp_loginout( $redirect = '', $display = true ) {
    	if ( ! is_user_logged_in() ) {
    		$link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
    	} else {
    		$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
    	}

    	if ( $display ) {
    		/**
    		 * Filters the HTML output for the Log In/Log Out link.
    		 *
    		 * @since 1.5.0
    		 *
    		 * @param string $link The HTML link content.
    		 */
    		echo apply_filters( 'loginout', $link );
    	} else {
    		/** This filter is documented in wp-includes/general-template.php */
    		return apply_filters( 'loginout', $link );
    	}
    }
    ```

[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#L586)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L586-L606)

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

 [apply_filters( ‘loginout’, string $link )](https://developer.wordpress.org/reference/hooks/loginout/)

Filters the HTML output for the Log In/Log Out link.

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

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

Retrieves the login URL.

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

Retrieves the logout URL.

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

Retrieves the translation of $text.

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

Checks and cleans a URL.

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

Determines whether the current visitor is a logged in user.

  | 
| [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 4 more](https://developer.wordpress.org/reference/functions/wp_loginout/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_loginout/?output_format=md#)

| Used by | Description | 
| [WP_Widget_Meta::widget()](https://developer.wordpress.org/reference/classes/wp_widget_meta/widget/)`wp-includes/widgets/class-wp-widget-meta.php` |

Outputs the content for the current Meta widget instance.

  |

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

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

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

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_loginout/?output_format=md#comment-content-611)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_loginout/#comment-611)
 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_loginout%2F%23comment-611)
     Vote results for this note: 2[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_loginout%2F%23comment-611)
 4.  **Basic Example**
 5.      ```php
         <p><?php wp_loginout(); ?></p>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_loginout%2F%3Freplytocom%3D611%23feedback-editor-611)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_loginout/?output_format=md#comment-content-612)
 8.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_loginout/#comment-612)
 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_loginout%2F%23comment-612)
     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_loginout%2F%23comment-612)
 10. **Add Log In/Out link to nav menu**
 11. Simply add this code to your parent or child themes _functions.php_ file to display
     a Log In/Out link in the secondary navigation menu of the Twenty Fourteen default
     theme for WordPress.
 12.     ```php
         add_filter( 'wp_nav_menu_secondary_items','wpdocs_loginout_menu_link' );
     
         /**
          * Append Login In/Out link to menu with a redirect to this page
          */
         function wpdocs_loginout_menu_link( $menu ) {
             $loginout = wp_loginout( $_SERVER['REQUEST_URI'], false );
             $menu .= $loginout;
             return $menu;
         }
         ```
     
 13. Other themes like Twenty Thirteen may require you to add a class to the code like
     this example.
 14.     ```php
         $loginout = '<li class="nav-menu" class="menu-item">'
         	. wp_loginout( $_SERVER['REQUEST_URI'], false )
         	. '</li>';
         ```
     
 15.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_loginout%2F%3Freplytocom%3D612%23feedback-editor-612)

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