我使用的是Wordpress的子主题,WooCommerce主题店面。
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' ); ?>我想更改顺序,以便product_search排在secondary_navigation之前。
我已经浏览了storefront文件,但找不到设置此顺序的位置,只能找到单独的项目。
有没有人可以帮我钩住或做些需要改变订单的事情?
发布于 2016-06-11 07:27:43
来自@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-11 00:09:53
为此,您需要首先使用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 );发布于 2019-04-19 19:48:39
不确定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 );https://stackoverflow.com/questions/37745795
复制相似问题