Skip to content

Instantly share code, notes, and snippets.

@claygriffiths
Created August 26, 2021 03:45
Show Gist options
  • Save claygriffiths/9485fedefbd909a155f077c088184821 to your computer and use it in GitHub Desktop.
Save claygriffiths/9485fedefbd909a155f077c088184821 to your computer and use it in GitHub Desktop.
Gravity Forms: Add Surrogate-Control header if Gravity Form is present on page
<?php
/**
* Set Surrogate-Control header on pages with Gravity Forms to prevent Varnish from caching.
*
* This requires Varnish to be configured to utilize Surrogate-Control when present.
*
* See the follow material for more details:
* * https://developer.fastly.com/reference/http-headers/Surrogate-Control/
* * https://book.varnish-software.com/4.0/chapters/VCL_Basics.html#vcl-backend-response
*/
add_action( 'gform_post_enqueue_scripts', function ( $forms ) {
// If HTTP headers have already been sent, we can't modify them.
if ( headers_sent() ) {
return;
}
header( 'Surrogate-Control: no-store' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment