By default after user log out WordPress, user will be redirect to the login page. This useful trick that allow you to stay on current page after logout of your WordPress website.
Adding following snippet to current theme’s functions.php file:
1 2 3 4 |
function hungpd_dot_name_logout_redirect( $logouturl, $redir ){ return $logouturl . '&redirect_to=' . get_permalink(); } add_filter( 'logout_url', 'hungpd_dot_name_logout_redirect', 10, 2 ); |
Above snippet works only on non-admin pages. To make this work on any page you should replace:
1 |
return $logouturl . '&redirect_to=' . get_permalink(); |
with
1 |
return $logouturl . '&redirect_to=http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
If you have any questions or comments, please feel free to comment below. Also, if you have better ideas, do share your thoughts, I would be happy to expand my knowledge.