简体   繁体   English

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

[英]Change order of items in Storefront Theme Header

I am using a child theme of the Wordpress, WooCommerce theme Storefront.我正在使用 Wordpress 的子主题,WooCommerce 主题店面。

Storefront header hooked functions are ordered this way: Storefront header 挂钩函数按以下方式排序:

<?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' ); ?>

I would like to change the order so the product_search comes before the secondary_navigation .我想更改顺序,以便product_search出现在secondary_navigation之前。

I have been through the storefront files and cannot find where this order is set, only the items individually.我已经浏览了店面文件,找不到此订单的设置位置,只能找到单独的项目。

Can anyone please help me to hook or do what is needed to change the order please?任何人都可以帮我挂钩或执行更改订单所需的操作吗?

The suggestion from @loictheaztec was missing the add_action as below - @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 );
}

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.为此,您首先需要使用remove_action()函数将其删除,然后使用add_action()函数再次挂钩它,将优先级从 40 更改为 25。

Priority 25 is located between:优先级 25 位于:
@hooked storefront_site_branding - priority 20 and @hooked storefront_secondary_navigation - priority 30 @hooked storefront_site_branding - 优先级 20 和@hooked storefront_secondary_navigation - 优先级 30

Paste this code snippet in function.php of your active theme folder (or better in your active child theme folder):将此代码片段粘贴到活动主题文件夹的 function.php 中(或更好地粘贴到活动子主题文件夹中):

remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );

Not sure if Loic got his answer to solve the duplicate issue, but to all that may need an answer, it needs to be wrapped in a function as suggested by Scott Eldo initially.不确定 Loic 是否得到了解决重复问题的答案,但对于所有可能需要答案的人来说,它需要按照 Scott Eldo 最初的建议封装在一个函数中。

So...所以...

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

as opposed to just putting it in function.php as such...而不是像这样把它放在function.php中......

remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );

I tried editing the accepted answer, got rejected...我尝试编辑接受的答案,但被拒绝了...

Every answer in this post has an error, the function name is not coincident with the add_action command....这个帖子里的每个答案都有一个错误,函数名和add_action命令不一致....

So, it should be...所以,应该是...

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

You can remove the actions, then add them in the order you would like them to appear:您可以删除这些操作,然后按照您希望它们出现的顺序添加它们:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM