Wordpress已经完成了正常程序的评估wp_head
当它到达小部件时。这个dynamic_sidebar_params
过滤器也只会在那时调用,因此它对获取css
在头部。Here\'这是我早些时候写的关于这个问题的东西。
要在头部包含来自小部件设置的信息,您必须使用在上激活的功能直接访问设置init
行动Beware 我没有测试以下内容,不知道是否会出现任何并发症。
所有小部件设置都存储在一个名为$wp_registered_widgets
, 遗憾的是,没有很好的记录(大概是因为你不应该弄乱它)。数据结构是这样的(props @shibashake, 但可能会在没有警告的情况下更改):
Array (
[archives-1] => Array (
[name] => Archives
[id] => archives-1
[callback] => Array (
[0] => WP_Widget_Archives Object (
[id_base] => archives
[name] => Archives
[widget_options] => Array (
[classname] => widget_archive
[description] => A monthly archive of your blog’s posts )
[control_options] => Array (
[id_base] => archives )
[number] => 1
[id] => archives-1
[updated] =>
[option_name] => widget_archives )
[1] => display_callback )
[params] => Array (
[0] => Array (
[number] => -1 )
)
[classname] => widget_archive
[description] => A monthly archive of your blog’s posts )
[text-8] => Array (
[name] => Text
[id] => text-8
[callback] => Array (
[0] => WP_Widget_Text Object (
[id_base] => text
[name] => Text
[widget_options] => Array (
[classname] => widget_text
[description] => Arbitrary text or HTML )
[control_options] => Array (
[id_base] => text
[width] => 400
[height] => 350 )
[number] => 8
[id] => text-8
[updated] =>
[option_name] => widget_text )
[1] => display_callback )
[params] => Array (
[0] => Array (
[number] => 8 )
)
[classname] => widget_text
[description] => Arbitrary text or HTML )
... )
现在,您可以访问此数据结构:
在数组中搜索以查找小部件的所有实例
在每个实例中查找已录制的样式设置,并使用wp_add_inline_style
.