DEV Community

Cover image for Redirect user to homepage after login/logout in WordPress
Chris Texe
Chris Texe

Posted on • Edited on • Originally published at madlon.eu

2 1

Redirect user to homepage after login/logout in WordPress

Let’s assume you have a WooCommerce shop in multisite WordPress installation. When user will logout then is redirected to main website from your multisite. User should be redirected to homepage of your store. If you want to redirect user to homepage after login or logout in WordPress put this code in functins.php file:

// redirect to home after login/logout
add_action('wp_logout','go_home');
function go_home(){
wp_redirect( home_url() );
exit();
}
add_action('wp_login','go_home_after_login');
function go_home_after_login(){
wp_redirect( home_url() );
exit();
}
view raw functions.php hosted with ❤ by GitHub

After saving the file user after logout will be redirected to homepage.

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay