0

I was using this code in my plugin to set a cookie if a condition was met, however after updating to Wordpress 4.0 I got the message:

Warning: Cannot modify header information - headers already sent

How can I set the cookie before headers are sent? This is my code:

    // Add Cookie if Admin
    if (current_user_can('manage_options') || !empty($_COOKIE["loggedAdmin"])) 
        {
        setcookie("loggedAdmin", "true", time()+3600*24*365);
        }
    }
  • Where is your code hooked to? Which action? – Otto Sep 15 '14 at 18:32
  • hi I hooked it to init add_action('init', array('Pranalog_Analytics', 'detect_admins')); still I keep getting that error. Also it says the input started on functions.php but I see nothing wrong there – Lisandro Vaccaro Sep 15 '14 at 18:48
  • Look at the file it is pointing to. Perhaps it has a blank line at the top or bottom of the file that it should not have. – Otto Sep 15 '14 at 21:05
  • I checked but there was none. I copied the content to a new file and the problem was gone, I think it might have been a problem with utf bom – Lisandro Vaccaro Sep 16 '14 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.