0

I get this error when trying to set a cookie on a WP page.

Warning: Cannot modify header information - headers already sent by(...)

Any help here? It worked fine when I did the php outside of wordpress, but when I move it in, it broke. Nothing special about the cookie(very basic).

So how do I get the cookie to set?

1

You set the cookie too late. You can use any action before template_include to set a cookie, after that there is already HTML output, and no further headers can be set.

Example:

add_action( 'template_redirect', function()
{
    setcookie( 'test', 1 );
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.