Created
March 2, 2023 22:54
-
-
Save marktenney/bcf54a903453500b45c02289cbfb1bb9 to your computer and use it in GitHub Desktop.
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 | |
add_filter( 'rwmb_meta_boxes', 'dgtl_register_meta_boxes_cache_exclusion' ); | |
function dgtl_register_meta_boxes_cache_exclusion( $meta_boxes ) { | |
$meta_boxes[] = [ | |
'title' => 'Cache Control', | |
'id' => 'cache-control', | |
'post_types' => [ | |
'post', | |
'page' | |
], | |
'context' => 'side', | |
'fields' => [ | |
[ | |
'type' => 'switch', | |
'name' => esc_html__( 'Exclude from Cache', 'online-generator' ), | |
'id' => 'cache_exclusion', | |
'desc' => esc_html__( 'Selecting this option will exclude this post from the cache. Select this if the post includes a complex form like payment processing.', 'online-generator' ), | |
], | |
], | |
]; | |
return $meta_boxes; | |
} | |
function dgtl_exclude_from_cache() { | |
if (get_post_meta($post_id, 'cache_exclusion', true)) { | |
header( 'do-not-cache: true' ); | |
} | |
} | |
add_action( 'send_headers', 'dgtl_exclude_from_cache' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment