Created
August 26, 2021 03:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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