wp_loginout

Display the Log In/Out link.

Description

(string|void) wp_loginout( (string) $redirect = '', (constant) $echo = true ); 

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.

Returns (string|void)

String when retrieving.

Parameters (2)

0. $redirect — Optional. (string) => ''
Path to redirect to on login/logout.
1. $echo — Optional. (constant) => true
Default to echo and not return the link.

Usage

  1. if ( !function_exists( 'wp_loginout' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional path to redirect to on login/logout. 
  5. $redirect = ''; 
  6.  
  7. // Default to echo and not return the link. 
  8. $echo = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_loginout($redirect, $echo); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function wp_loginout($redirect = '', $echo = true) { 
  2. if ( ! is_user_logged_in() ) 
  3. $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>'; 
  4. else 
  5. $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>'; 
  6.  
  7. if ( $echo ) { 
  8. /** 
  9. * Filters the HTML output for the Log In/Log Out link. 
  10. * @since 1.5.0 
  11. * @param string $link The HTML link content. 
  12. */ 
  13. echo apply_filters( 'loginout', $link ); 
  14. } else { 
  15. /** This filter is documented in wp-includes/general-template.php */ 
  16. return apply_filters( 'loginout', $link );