Skip to content

Instantly share code, notes, and snippets.

@henshaw
Last active October 19, 2021 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henshaw/29b34807f393f24c9a258db685a987e6 to your computer and use it in GitHub Desktop.
Save henshaw/29b34807f393f24c9a258db685a987e6 to your computer and use it in GitHub Desktop.
The WordPress HTTP header must have cache-control set to must-revalidate for Signed Exchanges (SXG) to work with Cloudflare on Google Search. This code must be added to the theme's functions.php file. Additionally, the Browser Cache TTL on Cloudflare must be set to Respect Existing Headers.
/**
* Add cache-control headers to response
*/
function add_cache_control_headers() {
if (!is_admin()) {
header("Cache-Control: public, must-revalidate, max-age=3600");
}
}
add_action( 'template_redirect', 'add_cache_control_headers' );
@henshaw
Copy link
Author

henshaw commented Oct 19, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment