Log out to home page

smartsovereign
18 May 2022

This snippet is good for e-commerce stores or anywhere that customers can be logged in, it ensures they don’t see the default WordPress login page, but are instead taken to the home page.

<?php

/**
 * Snippet Name: Redirect to homepage after logout
 * Snippet URL: https://www.wpcustoms.net/snippets/redirect-homepage-logout/
 */
  function wpc_auto_redirect_after_logout(){
  wp_redirect( home_url() );
  exit();
}
add_action('wp_logout','wpc_auto_redirect_after_logout');

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy