nocache_headers
云策文档标注
概述
nocache_headers 是一个 WordPress 过滤器,用于修改控制缓存禁止的 HTTP 头信息。它允许开发者自定义或移除默认的防缓存头,常用于特定页面或场景下调整缓存行为。
关键要点
- nocache_headers 过滤器用于过滤防缓存 HTTP 头,参数为 $headers 数组。
- 相关函数 wp_get_nocache_headers() 用于获取默认的防缓存头信息。
- 该过滤器自 WordPress 2.8.0 版本引入。
代码示例
// 定义 nocache_headers 回调函数
function remove_nocache_headers( $headers ) {
// 在此处进行过滤操作...
return $headers;
};
// 添加过滤器
add_filter( 'nocache_headers', 'remove_nocache_headers', 10, 1 );注意事项
通常,当不希望内容被缓存时,可以调用 WordPress 的 nocache_headers() 函数。
原文内容
Filters the cache-controlling HTTP headers that are used to prevent caching.
Description
See also
Parameters
$headersarray-
Header names and field values.
Source
$headers = (array) apply_filters( 'nocache_headers', $headers );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 3 content
prajaktag
// define the nocache_headers callback function remove_nocache_headers( $headers ) { // make filter magic happen here... return $headers; }; // add the filter add_filter( 'nocache_headers', 'remove_nocache_headers', 10, 1 );Skip to note 4 content
prajaktag
Typically, you can call WordPress’ nocache_headers() function when you don’t want content to be cached.