2

我使用 Storefront 的子主题。我已经编辑了header.php文件的副本,并在删除导航栏后添加了额外的 div:

<header id="masthead" class="site-header" role="banner" style="<?php storefront_header_styles(); ?>">
    <div class="col-full">

        <?php
        /**
         * Functions hooked into storefront_header action
         *
         * @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_wrapper       - 42
         * @hooked storefront_primary_navigation               - 50
         * @hooked storefront_header_cart                      - 60
         * @hooked storefront_primary_navigation_wrapper_close - 68
         */
    **remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );**
    **add_action('storefront_header', 'storefront_primary_navigation', 51);**

    **add_action('storefront_header', 'jk_storefront_header_content', 50);**        
    do_action( 'storefront_header' ); 

        ?>          
    </div>
</header><!-- #masthead -->

这似乎是正确的,但不是要删除和替换导航栏,而是我有旧导航栏额外的 div 和另一个导航,这意味着导航栏从未被删除......</p>

如何解决这个问题?

4

1 回答 1

3

您无需header.php在子主题中覆盖...</p>

要正确使用remove_action(),您需要以这种方式将其嵌入到挂钩中的自定义函数中init

add_action('init', 'replace_storefront_primary_navigation' );
function replace_storefront_primary_navigation(){
    remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
    add_action('storefront_header', 'jk_storefront_header_content', 50);
}
function jk_storefront_header_content(){
    // your custom navigation code goes here
    echo '<span style="display:inline-block; padding:10px; border:solid 1px grey;">My custom mega menu goes Here</span>';
}

代码位于您的活动子主题(或活动主题)的 function.php 文件中。

经过测试并适用于 WooCommerce 店面主题。

于 2018-01-07T21:10:41.927 回答