I’m developing a custom logout page using templates (you know, creating simple pages and adding them “/* Template Name: MyTemplate */”). This way I can access all wp core features:
<?php /*Template Name: My Logout */
wp_logout();
?>
The problem is when I call this template using Ajax I’m getting the same warning:
Warning: Cannot modify header information – headers already sent by (output started at /XXX/mylogout.php:1) in /XXX/wp-includes/pluggable.php on line 697
Yes it’s a warning but the logout action is not done (if I try to access member page, I can without log in).
I’m have been reading about blank spaces in functions.php and similars but looks like all it’s fine. Maybe “Template Name…” comment??
Any ideas??
Thanks in advance.
You can create a logout link with:
where it will redirect you to the home page. You can replace it with a custom redirect page.
Check out the
wp_logout_url()
function in the Codex here.Another solution is to check logout page on the
init
hook to avoid headers already sent error…