Home  »  CodeGuidesLibrariesProgrammingSnippetsTechnology   »   Logout to Home Page in WordPress

Logout to Home Page in WordPress

Posted: May 11, 2022 | by Michael Bright

Use this code snippet to logout to home page in WordPress.

The WordPress logout link:

<a href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>

WordPress logout to home page in functions.php theme file:

function redirect_home_after_logout(){
   wp_safe_redirect( home_url() );
   exit;
}
add_action( 'wp_logout', 'redirect_home_after_logout' );

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.