Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
widgets_init - 在注册所有默认WordPress小工具后触发 - WordPress钩子 - WordPress动力
当前浏览:首页 / WordPress钩子 / widgets_init

do_action( 'widgets_init' )

在注册所有默认WordPress小工具后触发


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "9c47d48e79d561c86f311dbc232023fc" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "0ae79f97552e7204594f6cb278768be9" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

init

  • admin_init 在初始化管理界面或脚本时触发
  • init 在WordPress完成加载后未发送头数据之前触发
  • widgets_init 在注册所有默认WordPress小工具后触发

widget 小工具



源码

查看源码 官方文档


更新日志

版本描述
2.2.0开始引入

使用示例

  • 示例1

    例如,用于注册边栏:

    function mytheme_widgets_init() {
    	register_sidebar( array(
    		'name'          => __( 'Single Post Widgets', 'textdomain' ),
    		'id'            => 'mytheme-single-post-widgets',
    		'description'   => __( 'Widgets in this area will be shown under your single posts, before comments.', 'textdomain' ),
    		'before_widget'	=> '',
    		'after_widget'	=> '',
    		'before_title'	=> '',
    		'after_title'	=> '',
        ) );
    }
    add_action( 'widgets_init', 'mytheme_widgets_init' );
    
  • 示例2

    您应该注意,widgets_init钩子是作为init钩子的一部分启动的,优先级为1。

    这意味着它将在您以默认优先级添加到init挂钩的任何代码之前触发。