I want to use another link for logout because I have /wp-admin/*
protected with htpassword. Is there a way to do this? Something like creating a custom page like site.com/logout
then use it as my new logout link?
Thanks!
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI want to use another link for logout because I have /wp-admin/*
protected with htpassword. Is there a way to do this? Something like creating a custom page like site.com/logout
then use it as my new logout link?
Thanks!
You can filter 'logout_url'
and return a custom value if you are in the admin area:
add_filter( 'logout_url', 'wpse_58453_logout_url' );
function wpse_58453_logout_url( $default )
{
// set your URL here
return is_admin() ? 'http://example.com/custom' : $default;
}
<?php echo wp_logout_url( ); ?>
it gives me a the right logout url which is mysite.com/logout but when i click on it it will just redirect me to the /logout WordPress page. Do i need to setup any code on my /logout
page on wordpress?
– tiltdown
Jul 14 '12 at 8:27
This worked for me redirecting to the home page:
add_action('wp_logout','unlog');
function unlog(){
wp_redirect( site_url() );
exit();
}
I think you should add rewrite rule in your htaccess file like this.
RewriteRule ^logout/(.*) /wp-login.php?action=logout&_wpnonce=$1 [QSA,L]
I found the solution here: https://www.kmbytes.com/wordpress-logout-redirect-filter/
And it is working great!
add_filter( 'logout_url', 'my_logout_url' );
function my_logout_url( $url ) {
$redirect = home_url();
return $url.'&redirect_to='.$redirect;
}
Cheers!