简体   繁体   中英

redirect to login page when user press logout in wordpress

I have a problem when user clicks on logout, he's getting redirected to wordpress's login page, whereas I want him to be redirected to website's login page.

Here's the header link I'm trying, but it's not working :

header("Location:http://".$_SERVER['HTTP_HOST']."/ngo/wp-login.php?action=logout".
           "&redirect_to=http://".$_SERVER['HTTP_HOST']."/ngo/?page_id=56");

get_header();

ngo/?page_id=56 is the permalink to the login page.

Something like this:

add_action( 'wp_logout', 'my_redirect' );

function my_redirect() {
    wp_redirect( 'http://whatever_you_like.com' );
}

WordPress has a hook system where you can hook to most significant moments. With the code above we simply say we want to handle something on log out and where is our handler callback.

I can give you also OOP style, if you have class.

Try using the WP function for that purpose. The parameter is the URL to redirect to on logout. :

<?php echo wp_logout_url( $redirect ); ?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM