钩子文档

get_search_form

💡 云策文档标注

概述

get_search_form 是一个 WordPress 过滤器,用于修改搜索表单的 HTML 输出。它允许开发者自定义搜索表单的显示内容和参数。

关键要点

  • 过滤器名称:get_search_form
  • 参数:$form(搜索表单的 HTML 输出字符串)和 $args(构建搜索表单的参数数组)
  • 用途:通过 apply_filters 调用,可调整搜索表单的 HTML 或基于参数进行定制
  • 相关函数:get_search_form() 用于显示搜索表单

注意事项

  • 参数 $args 从 WordPress 5.5.0 版本开始添加,包含 echo(是否回显表单)和 aria_label(ARIA 标签)等选项
  • 使用此过滤器时,需确保兼容不同 WordPress 版本,特别是 $args 参数的可用性

📄 原文内容

Filters the HTML output of the search form.

Parameters

$formstring
The search form HTML output.
$argsarray
The array of arguments for building the search form.
See get_search_form() for information on accepted arguments.

More Arguments from get_search_form( … $args )

Array of display arguments.

  • echo bool
    Whether to echo or return the form. Default true.
  • aria_label string
    ARIA label for the search form. Useful to distinguish multiple search forms on the same page and improve accessibility.

Source

$result = apply_filters( 'get_search_form', $form, $args );

Changelog

Version Description
5.5.0 The $args parameter was added.
2.7.0 Introduced.