【问题标题】:Adding widget area to top header将小部件区域添加到顶部标题
【发布时间】:2017-08-15 09:07:57
【问题描述】:

我正在尝试在我当前的店面主题中添加一个小部件区域。我使用了下面的代码,但它将小部件放在我当前的顶部标题下方,这称为辅助导航。我使用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');
  }
}

【问题讨论】:

    标签: php wordpress woocommerce widget storefront


    【解决方案1】:

    您需要在51 和59 之间更改优先级,例如:

    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
    

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

    【讨论】:

      猜你喜欢
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 2015-07-17
      • 2019-10-19
      • 2018-02-24
      相关资源
      最近更新 更多