最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Logout after clicking URL link results in "headers already sent" error

programmeradmin3浏览0评论

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\wordpress\wp-includes\formatting.php:5688) in D:\xampp\htdocs\wordpress\wp-includes\pluggable.php on line 961

I am using this function

if(isset($_GET['logout']))
{
    //echo "test";
    //die();
    wp_logout();
    wp_redirect("http://localhost:2124/wordpress/game/");
    exit;
    //wp_logout_url("http://localhost:2124/wordpress/logout_custom");
    //exit();
    //die();
    //wp_redirect(site_url().'/login');
    //return "<script> location.replace('".site_url()."/login');</script>"; 
    //exit();
    //wp_redirect(site_url()."/login/");
}

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\wordpress\wp-includes\formatting.php:5688) in D:\xampp\htdocs\wordpress\wp-includes\pluggable.php on line 961

I am using this function

if(isset($_GET['logout']))
{
    //echo "test";
    //die();
    wp_logout();
    wp_redirect("http://localhost:2124/wordpress/game/");
    exit;
    //wp_logout_url("http://localhost:2124/wordpress/logout_custom");
    //exit();
    //die();
    //wp_redirect(site_url().'/login');
    //return "<script> location.replace('".site_url()."/login');</script>"; 
    //exit();
    //wp_redirect(site_url()."/login/");
}
Share Improve this question edited Dec 17, 2019 at 14:37 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Dec 16, 2019 at 18:02 Waqar HussainWaqar Hussain 1 1
  • You should do redirects within a hook before content is rendered. Try running that code inside a template_redirect hooked function. – Carlos Faria Commented Dec 16, 2019 at 18:31
Add a comment  | 

1 Answer 1

Reset to default 1

You should do redirects within a hook before content is rendered. Try running that code inside a template_redirect hooked function.

Something like this:

add_action( 'template_redirect', 'my_redirects', 5 );
function my_redirects(){
    // Your code here
}
发布评论

评论列表(0)

  1. 暂无评论