I'm trying to change the cache-control header of a specific post (1234). I tried adding the following to the end of my functions.php:

add_filter('wp_headers', 'wp_test_headers');
function wp_test_headers($headers)
    if ( is_single ( 1234) ) {
       $headers['Cache-Control']="no-store, no-cache, must-revalidate, max-age=0";
    return $headers;

However when I open the page of the post in my browser, the condition is never met. Should I be adding the filter elsewhere, or is there another issue?

  • 1
    if it's the page post type, you need is_page. – Milo Jan 6 '18 at 22:05
  • Is there such thing as a default post type? I created it by going to the posts sidebar and adding a new post. – simplicity Jan 6 '18 at 22:07

from How can I change HTTP headers only to posts of a specific category from a plugin:

add_action( 'template_redirect', 'update_header_cache' );
function update_header_cache() {
    if( is_single( 1234) ) {
        header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
        header('Pragma: no-cache');
        header('Expires: Thu, 01 Dec 1990 16:00:00 GMT');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.