将小部件区域添加到顶部标题

时间:2016-05-26 09:07:33

标签: php wordpress woocommerce widget storefront

我正在尝试在当前店面主题中添加小部件区域。我使用下面的代码,但它将小部件放在我当前的top-header之下,称为辅助导航。我使用these hooks来制作代码。

应用时,它会在辅助导航下面创建一个小部件区域,但我需要它在辅助导航中。任何帮助将不胜感激。

// Adding the widget area.
if (function_exists('register_sidebar')) {
    register_sidebar(array(
    'name' => 'Extra Header Widget Area',
    'id' => 'extra-widget-area',
    'description' => 'Extra widget area after the header',
    'before_widget' => '<div class="widget my-extra-widget">',
    'after_widget' => '</div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>'
    ));
}


// placing the widget
add_action ('storefront_header', 'add_my_widget_area', 10);
function add_my_widget_area() {
  if (function_exists('dynamic_sidebar')) {
    dynamic_sidebar('Extra Header Widget Area');
  }
}

1 个答案:

答案 0 :(得分:1)

您需要更改5159之间的优先级,例如:

add_action ('storefront_header', 'add_my_widget_area', 55);

因为在storefront_header挂钩中,这些是当前优先级:

for 'storefront_header' hook:
@hooked ‘storefront_skip_links’, 0
@hooked ‘storefront_social_icons’, 10
@hooked ‘storefront_site_branding’, 20
@hooked ‘storefront_secondary_navigation’, 30
@hooked ‘storefront_product_search’, 40
@hooked ‘storefront_primary_navigation’, 50
@hooked ‘storefront_header_cart’, 60

然后,您需要在某些规则中使用!important强制执行自定义css规则来优化显示。