钩子文档

search_form_args

💡 云策文档标注

概述

search_form_args 是一个 WordPress 过滤器钩子,用于修改生成搜索表单时使用的参数数组。它允许开发者在调用 get_search_form() 函数时自定义表单的显示和行为。

关键要点

  • 这是一个过滤器钩子,名称为 search_form_args,用于过滤搜索表单的参数数组。
  • 参数 $args 是一个数组,包含构建搜索表单的配置选项,如 echo 和 aria_label。
  • 与 get_search_form() 函数紧密相关,可用于增强表单的可访问性和定制化。

代码示例

$args = apply_filters( 'search_form_args', $args );

注意事项

此钩子自 WordPress 5.2.0 版本引入,使用时需确保兼容性。参数 aria_label 有助于区分同一页面上的多个搜索表单,提升无障碍访问性。


📄 原文内容

Filters the array of arguments used when generating the search form.

Parameters

$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

$args = apply_filters( 'search_form_args', $args );

Changelog

Version Description
5.2.0 Introduced.