0
<?php
    if(is_user_logged_in()){
        //do something
    }else{
        wp_redirect( wp_login_url() );
        exit;
    }
?>

So I try to do that, but get a header already sent error by Divi.

Warning: Cannot modify header information - headers already sent by (output started at /public_html/wp-content/themes/Divi/header.php:1) in /public_html/wp-includes/pluggable.php on line 1265

Is this a common error, any ideas to fix that?

  • 1
    Does this answer your question? [How to fix "Headers already sent" error in PHP](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Prabhjot Singh Kainth Mar 09 '20 at 11:23

1 Answers1

2

This is caused by the page showing content before the PHP script is released. This can be a lot of things, if there's HTML being shown before the script I think it can do this. I've seen it happen before with trailing whitespace after closing a php tag too.