Hi @r0cc4t0
How did you add the Cache-Control header exactly? Because I just tested this on my local test environment and it worked fine when I did it like this:
function wprc_add_cacheable_request_headers( $cacheable_headers ) {
$cacheable_headers['wp/v2/posts'] = 'Cache-Control';
return $cacheable_headers;
}
add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);
Hi @rockfire
I used this code:
function wprc_add_postmeta_cache_control( $cacheable_headers ) {
$cacheable_headers['custom/v1/post_meta'] = 'Cache-Control';
return $cacheable_headers;
}
add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_postmeta_cache_control', 10, 1);
I would like to know how I can modify the content, e.g., {“Cache-Control”:null} to {“Cache-Control”:”max-age=604800″}
Hi @r0cc4t0
That code should be enough, if the header is null then I think WordPress isn’t receiving the header at all.
Hi @rockfire
Could I modify the value of this header with wp_rest_cache/cache_headers?
Hi @r0cc4t0
Yes you could modify it with that filter, but if WordPress isn’t receiving the header I don’t knwo how you would want to modify it to the correct value?