Skip to content

Instantly share code, notes, and snippets.

@cyberhobo
Last active June 9, 2021 15:25
Show Gist options
  • Save cyberhobo/40122f51fce2e4eda20e346460a10c5f to your computer and use it in GitHub Desktop.
Save cyberhobo/40122f51fce2e4eda20e346460a10c5f to your computer and use it in GitHub Desktop.
Example of excluding a couple of checkout pages from Pantheon caching in a WordPress must-use plugin:
<?php
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) :
// Disable caching on checkout pages as per https://pantheon.io/docs/cache-control/
$regex_path_match = '#/foundation/donation-options/(checkout|shopping-cart)#';
if (preg_match($regex_path_match, $_SERVER['REQUEST_URI'])) {
// Use a later priority to make sure it runs after native Pantheon caching
add_action( 'send_headers', 'cth_add_header_nocache', 50 );
}
function cth_add_header_nocache() {
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
}
endif; # Ensuring that this is on Pantheon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment