钩子文档

the_widget

💡 云策文档标注

概述

the_widget 是一个 WordPress 动作钩子,在通过 the_widget() 函数渲染小部件之前触发。它允许开发者在特定小部件输出前执行自定义代码。

关键要点

  • 钩子名称:the_widget
  • 触发时机:仅在调用 the_widget() 函数时触发,不适用于侧边栏中的小部件渲染
  • 参数:$widget(小部件类名)、$instance(小部件实例设置)、$args(侧边栏参数数组)
  • 用途:用于在小部件渲染前进行干预或添加功能

注意事项

  • 此钩子仅与 the_widget() 函数关联,不影响常规侧边栏小部件渲染
  • 开发者需确保代码兼容性,避免与其他钩子冲突

📄 原文内容

Fires before rendering the requested widget.

Parameters

$widgetstring
The widget’s class name.
$instancearray
The current widget instance’s settings.
$argsarray
An array of the widget’s sidebar arguments.

Source

do_action( 'the_widget', $widget, $instance, $args );

Changelog

Version Description
3.0.0 Introduced.

User Contributed Notes