admin管理员组文章数量:1122832
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?
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?
Share Improve this question edited Jan 6, 2018 at 22:31 simplicity asked Jan 6, 2018 at 21:57 simplicitysimplicity 12 bronze badges 2 |1 Answer
Reset to default 0from 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');
}
}
本文标签: filtersModify wp headers on specific page
版权声明:本文标题:filters - Modify wp headers on specific page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296241a1929745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
page
post type, you needis_page
. – Milo Commented Jan 6, 2018 at 22:05