Skip to content
  • Log In
  • Register
WordPress.org
  • News
  • Download & Extend
    • Get WordPress
    • Themes
    • Patterns
    • Plugins
    • Openverse
    • Mobile
    • Hosting
  • Learn
    • Learn WordPress
    • Documentation
    • Forums
    • WordPress.tv
    • Developers
  • Community
    • Make WordPress
    • WordCamp
    • Meetups
    • Photo Directory
    • Job Board
    • Five for the Future
  • About
    • About WordPress
    • Showcase
    • Gutenberg
    • Enterprise
    • WordPress Swag Store
  • Get WordPress
Get WordPress

Developer Resources

Browse: Home / Reference / Hooks / logout_redirect

apply_filters( 'logout_redirect', string $redirect_to, string $requested_redirect_to, WP_User $user )

Filters the log out redirect URL.

Contents

  • Parameters
  • Source
  • Changelog
  • User Contributed Notes

Parameters

$redirect_to string
The redirect destination URL.
$requested_redirect_to string
The requested redirect destination URL passed as a parameter.
$user WP_User
The WP_User object for the user that's logging out.

Top ↑

Source

File: wp-login.php. View all references

$redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );

View on Trac View on GitHub


Top ↑

Changelog

Changelog
Version Description
4.2.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
    Contributed by Gabor Lippert — 1 year ago

    Logout function (that actually works) according user role:

    function wpdocs_logout_redirect( $redirect_to, $requested_redirect_to, $user ) {
    
        $user_roles = $user->roles;
        $user_has_admin_role = in_array( 'administrator', $user_roles );
    
    	if ( $user_has_admin_role ) :
    		$redirect_to = admin_url();
    	else:
    		$redirect_to = home_url();
    	endif;
    
    	return $redirect_to;
    }         
    add_filter( 'logout_redirect', 'wpdocs_logout_redirect', 9999, 3 );
    Log in to add feedback
  2. Skip to note 2 content
    You must log in to vote on the helpfulness of this noteVote results for this note: -4You must log in to vote on the helpfulness of this note
    Contributed by mikelast — 4 years ago

    taken from the article at sourcexpress.com/logout_redirect-filter-hook-introduced-in-wordpress-4-2

    This filter comes with 3 parameters, string $redirect_to The redirect destination URL, string $requested_redirect_to The requested redirect destination URL passed as parameter, WP_User $user WP_User object for the user logging out.

    Using the third param we can target specific redirect locations depending on the user, user role etc.

    function se_logout_redirect( $redirect_to, $requested_redirect_to, $user ) {
    	if ( in_array( 'subscriber', $user->roles ) ) {
    		$requested_redirect_to = home_url();
    	} else {
    		$requested_redirect_to = home_url( '/hello-world' );
    	}
     
    	return $requested_redirect_to;
     
    }
    add_filter( 'logout_redirect', 'se_logout_redirect', 10, 3 );
    Log in to add feedback

You must log in before being able to contribute a note or feedback.

  • About
  • News
  • Hosting
  • Donate
  • Swag
  • Documentation
  • Developers
  • Get Involved
  • Learn
  • Showcase
  • Plugins
  • Themes
  • Patterns
  • WordCamp
  • WordPress.TV
  • BuddyPress
  • bbPress
  • WordPress.com
  • Matt
  • Privacy
  • Public Code
WordPress.org
WordPress.org
  • Visit our Facebook page
  • Visit our Twitter account
  • Visit our Instagram account
  • Visit our LinkedIn account
Code is Poetry

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.