首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改Storefront主题标题中项目的顺序

更改Storefront主题标题中项目的顺序
EN

Stack Overflow用户
提问于 2016-06-10 18:21:53
回答 5查看 5.3K关注 0票数 5

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

Storefront header挂钩函数的顺序如下:

代码语言:javascript
复制
<?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_search排在secondary_navigation之前。

我已经浏览了storefront文件,但找不到设置此顺序的位置,只能找到单独的项目。

有没有人可以帮我钩住或做些需要改变订单的事情?

EN

回答 5

Stack Overflow用户

发布于 2016-06-11 07:27:43

来自@loictheaztec的建议缺少add_action,如下所示-

代码语言:javascript
复制
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 );
}
票数 5
EN

Stack Overflow用户

发布于 2016-06-11 00:09:53

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

优先级25位于以下各项之间:

@hooked storefront_site_branding -优先级20和@hooked storefront_secondary_navigation -优先级30

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

代码语言:javascript
复制
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
票数 1
EN

Stack Overflow用户

发布于 2019-04-19 19:48:39

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

所以..。

代码语言:javascript
复制
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中。

代码语言:javascript
复制
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37745795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档