apply_filters( ‘logout_redirect’, string $redirect_to, string $requested_redirect_to, WP_User $user )

Filters the log out redirect URL.


The redirect destination URL.
The requested redirect destination URL passed as a parameter.
The WP_User object for the user that’s logging out.


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



User Contributed Notes

  1. Skip to note 3 content

    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();
    		$redirect_to = home_url();
    	return $redirect_to;
    add_filter( 'logout_redirect', 'wpdocs_logout_redirect', 9999, 3 );
  2. Skip to note 4 content

    taken from the article at

    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 );

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