I have a cookie with data that I'm utilizing to populate a Gravity Forms form. However, after the form has been successfully submitted, I'd like to unset (or more accurately, expire) that cookie.

What I've tried

Initially, I thought the gform_after_submission hook would work. I tried simply that pointing to a function that does the following:

public static function clearItems() {
    setcookie('items', '', time() - 86400, '/');

The problem is that this hook is executed after the headers and therefore the updated value and expiration are not set.


Is there any way to accomplish this (maybe I'm missing a hook of some kind that would work better)?

Another possibility that I've considered is to redirect to page and handle it there but I'd prefer not do handle it this way.

1 Answer 1


I ran this code to try setting a cookie on the gform_after_submission hook and it worked as expected.

add_action( 'gform_after_submission', function() {
    setcookie( 'boom', 'boom', time() + 3600, '/' );
} );

The headers should not already be sent when the gform_after_submission action is triggered. If you're getting a warning about this, there might be something else outputting something to the page earlier in the process.

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