Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Conditional logout redirect

On logout, redirect different users to different locations, using ‘logout_redirect’ filter.

function conditional_logout_redirect( $redirect_to, $requested_redirect_to, $user ) {
	
	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
	
		if ( in_array( 'subscriber', $user->roles ) ) {
	
			// subscriber role redirected to homepage
			return home_url();
	
		} else {
	
			// other roles redirected to the original destination URL
			return $redirect_to;
	
		}
	
	}
	
	return $redirect_to;
	
}
add_filter( 'logout_redirect', 'conditional_logout_redirect', 10, 3 );