5

我正在使用 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' ); ?>

我想更改顺序,以便product_searchsecondary_navigation.

我浏览了店面文件,找不到此订单的设置位置,只能找到单独的项目。

任何人都可以帮我挂钩或做更改订单所需的操作吗?

4

5 回答 5

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 );
}
于 2016-06-10T23:27:42.700 回答
1

不确定 Loic 是否得到了解决重复问题的答案,但对于所有可能需要答案的人,它需要按照 Scott Eldo 最初的建议包装在一个函数中。

所以...

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 );
}

而不是仅仅把它放在function.php中......

remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
于 2019-04-19T11:48:38.540 回答
1

For that purpose you will need first to remove it with remove_action() function and then you will hook it again with add_action() function, changing the priority from 40 to 25.

Priority 25 is located between:
@hooked storefront_site_branding - priority 20 and @hooked storefront_secondary_navigation - priority 30

Paste this code snippet in function.php of your active theme folder (or better in your active child theme folder):

remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
于 2016-06-10T16:09:52.893 回答
1

我尝试编辑接受的答案,被拒绝...

这篇文章中的每一个答案都有一个错误,函数名与 add_action 命令不重合....

所以,应该是...

add_action( 'init' , 'change_header_order' , 15 );
function change_header_order() {
        remove_action( 'storefront_header', 'storefront_product_search', 40 );
        add_action( 'storefront_header', 'storefront_product_search', 25 );
}
于 2020-10-16T22:49:59.767 回答
0

您可以删除这些操作,然后按照您希望它们出现的顺序添加它们:

add_action( 'init' , 'mh_add_and_remove' , 15 );
function mh_add_and_remove() {
    remove_action( 'storefront_header','storefront_header_container', 0 );
    remove_action( 'storefront_header','storefront_skip_links', 5 );
    remove_action( 'storefront_header', 'storefront_site_branding', 20);
    remove_action( 'storefront_header','storefront_secondary_navigation', 30);
    remove_action( 'storefront_header', 'storefront_product_search', 40 );
    remove_action( 'storefront_header', 'storefront_header_container_close', 4);

    add_action( 'storefront_header','storefront_header_container', 69 );
    add_action( 'storefront_header','storefront_skip_links', 90 );
    add_action( 'storefront_header', 'storefront_site_branding', 91);
    add_action( 'storefront_header','storefront_secondary_navigation', 92);
    add_action( 'storefront_header', 'storefront_product_search', 93 );
    add_action( 'storefront_header', 'storefront_header_container_close', 94);
}
于 2021-02-11T14:19:13.900 回答