我正在使用Wordpress,WooCommerce主题店面的儿童主题。
Storefront标头挂钩函数以这种方式排序:
<?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
之前。
我浏览过店面文件,找不到此订单的设置位置,只能找到单独的商品。
有人可以帮我勾选或做些什么来改变订单吗?
答案 0 :(得分:4)
来自@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 );
}
答案 1 :(得分: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 );
答案 2 :(得分: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 );
}
答案 3 :(得分:0)
不确定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 );
答案 4 :(得分: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);
}