Modify wp headers on specific page

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?

Topic http headers filters Wordpress

Category Web


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');
    }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.