钩子文档

exit_on_http_head

💡 云策文档标注

概述

exit_on_http_head 是一个 WordPress 过滤器,用于控制是否允许 'HEAD' 请求生成页面内容,以提高性能。

关键要点

  • 该过滤器允许在 'HEAD' 请求时提前退出,避免加载页面内容,从而提升性能。
  • 参数 $exit 是一个布尔值,默认为 true,表示默认情况下 'HEAD' 请求不生成内容。
  • 过滤器在 WordPress 3.5.0 版本中引入。

代码示例

if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) {
    // 在此处添加退出逻辑
}

📄 原文内容

Filters whether to allow ‘HEAD’ requests to generate content.

Description

Provides a significant performance bump by exiting before the page content loads for ‘HEAD’ requests. See #14348.

Parameters

$exitbool
Whether to exit without generating any content for 'HEAD' requests. Default true.

Source

if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) {

Changelog

Version Description
3.5.0 Introduced.