更改店面主题标题中的项目顺序

Sco*_*ldo 4 php wordpress wordpress-theming storefront woocommerce

我正在使用Wordpress的子主题,WooCommerce主题店面。

店面标头挂钩函数的订购方式如下:

<?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
         */
        do_action( 'storefront_header' ); ?>
Run Code Online (Sandbox Code Playgroud)

我想更改顺序,以便product_search可以在之前secondary_navigation

我已经遍历了店面文件,无法找到设置此顺序的位置,只能找到单个项。

任何人都可以请我帮忙上钩或做些改变订单的事情吗?

Sco*_*ldo 5

@loictheaztec的建议缺少如下的add_action-

add_action( 'init' , 'add_and_remove' , 15 );
function mh_add_and_remove() {
        remove_action( 'storefront_header', 'storefront_product_search', 40 );
        add_action( 'storefront_header', 'storefront_product_search', 25 );
}
Run Code Online (Sandbox Code Playgroud)


Loi*_*tec 1

为此,您需要首先使用remove_action()函数删除它,然后再次使用它挂钩add_action(),将优先级从 40 更改为 25。

优先级 25 位于:
@hooked storefront_site_branding- 优先级 20 和@hooked storefront_secondary_navigation- 优先级 30之间

将此代码片段粘贴到活动主题文件夹的 function.php 中(或者更好地粘贴到活动子主题文件夹中):

remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
Run Code Online (Sandbox Code Playgroud)