【问题标题】:Change order of items in Storefront Theme Header更改店面主题标题中的项目顺序
【发布时间】:2016-10-11 06:39:22
【问题描述】:

我正在使用 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 之前。

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

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

【问题讨论】:

    标签: php wordpress woocommerce wordpress-theming storefront


    【解决方案1】:

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

    优先级 25 位于:
    @hooked storefront_site_branding - 优先级 20 和@hooked storefront_secondary_navigation - 优先级 30

    将此代码 sn-p 粘贴到您的活动主题文件夹的 function.php 中(或者更好的是在您的活动子主题文件夹中):

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

    【讨论】:

    • 谢谢。但是,remove_action 不起作用。我现在有两个 product_search。任何想法为什么它不会删除?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      不确定 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】:

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

        本帖每一个答案都有错误,函数名与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 );
        }
        

        【讨论】:

          【解决方案5】:

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

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

          【讨论】:

            猜你喜欢
            • 2017-08-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-04-11
            • 2014-03-12
            • 2023-03-14
            • 2019-03-20
            相关资源
            最近更新 更多