I have a plugin to inject httpfor injecting additional HTTP headers. It works fine. with the following CODE:
add_action( 'send_headers', 'jim_stop' );
function jim_stop() {
header( 'Cache-Control: no-store, no-cache, must-revalidate, max-age=0' );
header( 'Pragma: no-cache' );
header( 'Expires: Thu, 01 Dec 1994 16:00:00 GMT' );
}
NowIt sets the above HTTP headers to all the posts. However, I want to only inject the headers ononly to the pages inof a specific category X. For example, say the category slug is x
and id is 75
.
I've wrappedTo set the function inHTTP headers specific to the posts of category if ( x
, I've used in_category( 'x') ) {}
in conditional as follows:
add_action( 'send_headers', 'jim_stop' );
function jim_stop() {
if ( in_category( 'x' ) ) {
// category specific HTTP headers
}
}
but that didn't work.
I've also tried wrapping it into check the category like this:
$cat = get_query_var( 'cat' );
if ( $cat == '75' ) {
// category specific HTTP headers
}
and also like this:
global $post;
if ( in_category ( 'x', $post->ID ) ) {
// category specific HTTP headers
}
but those fail too.
Any ideas? How can I restrictAs the headerscategory check didn't work with the send_headers
action hook, I've tried to onlydo it with wp_headers
filter hook, like the category I want?following:
add_filter( 'wp_headers', 'add_header_xua' );
function add_header_xua( $headers ) {
if ( in_category( 'x' ) ) {
// category specific HTTP header changes
}
return $headers;
}
but it fails too. So my question is:
- How can I restrict the HTTP header changes only to the posts of a specific category?