wp_logout problem

I have added custom page '/member-logout/' in nav walker for user logout. When activated then the function 'render-logout' is fired

function render_logout() {
    if ( is_user_logged_in() ){
         wp_logout();
    } else {
        echo "You are not logged-in"; 
    }
}

the logout works but generates a lot of warnigns of

Warning: Cannot modify header information - headers already sent by (output started at /home/........./formatting.php:5081) in /home/s..../wp-includes/pluggable.php on line 915

and i cannot find what is at fault

but redirect after logout does not work

    public function redirect_after_logout() {
    $redirect_url = home_url( 'member-login' );
    wp_redirect( $redirect_url );
    exit;
}
add_action( 'wp_logout', 'redirect_after_logout' );

The logout link below works very well (no warnings) but this is not loaded automaticly.

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

Any idea how to run this link using wp_redirect or something similar?

Topic logout Wordpress

Category Web


You could create a custom Page template which contains only the logout code, no call to header.php etc. When you load the /member-logout/ page you're probably calling the default page.php template which is loading header.php etc. If instead you apply your custom Page template it will just perform the logout action and can then redirect, as no headers have been sent (headers being different than just header.php but as soon as you output any HTML, which is contained in header.php, you have headers which is preventing the redirect).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.