wp_logout_url

Retrieves the logout URL.

Description

(string) wp_logout_url( (string) $redirect = '' ); 

Returns the URL that allows the user to log out of the site.

Returns (string)

The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().

Parameters (1)

0. $redirect — Optional. (string) => ''
Path to redirect to on logout.

Usage

  1. if ( !function_exists( 'wp_logout_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Path to redirect to on logout. 
  5. $redirect = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_logout_url($redirect); 
  9.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function wp_logout_url($redirect = '') { 
  2. $args = array( 'action' => 'logout' ); 
  3. if ( !empty($redirect) ) { 
  4. $args['redirect_to'] = urlencode( $redirect ); 
  5.  
  6. $logout_url = add_query_arg($args, site_url('wp-login.php', 'login')); 
  7. $logout_url = wp_nonce_url( $logout_url, 'log-out' ); 
  8.  
  9. /** 
  10. * Filters the logout URL. 
  11. * @since 2.8.0 
  12. * @param string $logout_url The HTML-encoded logout URL. 
  13. * @param string $redirect Path to redirect to on logout. 
  14. */ 
  15. return apply_filters( 'logout_url', $logout_url, $redirect );