我如何更改产品 <h2>在 Woocommerce Storefront 到 <h3>? [英] How can I change the product <h2> in Woocommerce Storefront to <h3>?

查看:24
本文介绍了我如何更改产品 <h2>在 Woocommerce Storefront 到 <h3>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将子主题用于 Woocommerce 的店面主题.在首页,将特色产品的产品名称渲染为h2s.我想将这些更改为 h3s(SEO 原因).

I'm using a child theme to Woocommerce's Storefront theme. On the home page, it is rendering the product names of the featured products as h2s. I would like to change these to h3s (SEO reasons).

h2s 使用这个类:woocommerce-loop-product__title.我搜索了 Storefront 主题,发现该类的唯一地方是 CSS.

The h2s use this class: woocommerce-loop-product__title. I searched through the Storefront theme, and the only place I found that class was in CSS.

我查看了这个文件:/storefront/inc/storefront-template-functions.php 并找到了这个代码:

I looked in this file: /storefront/inc/storefront-template-functions.php and found this code:

if ( ! function_exists( 'storefront_featured_products' ) ) {
/**
 * Display Featured Products
 * Hooked into the `homepage` action in the homepage template
 *
 * @since  1.0.0
 * @param array $args the product section args.
 * @return void
 */
function storefront_featured_products( $args ) {

    if ( storefront_is_woocommerce_activated() ) {

        $args = apply_filters( 'storefront_featured_products_args', array(
            'limit'      => 4,
            'columns'    => 4,
            'orderby'    => 'date',
            'order'      => 'desc',
            'visibility' => 'featured',
            'title'      => __( 'We Recommend', 'storefront' ),
        ) );

        $shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_featured_products_shortcode_args', array(
            'per_page'   => intval( $args['limit'] ),
            'columns'    => intval( $args['columns'] ),
            'orderby'    => esc_attr( $args['orderby'] ),
            'order'      => esc_attr( $args['order'] ),
            'visibility' => esc_attr( $args['visibility'] ),
        ) ) );

        /**
         * Only display the section if the shortcode returns products
         */
        if ( false !== strpos( $shortcode_content, 'product' ) ) {

            echo '<section class="storefront-product-section storefront-featured-products" aria-label="' . esc_attr__( 'Featured Products', 'storefront' ) . '">';

            do_action( 'storefront_homepage_before_featured_products' );

            echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';

            do_action( 'storefront_homepage_after_featured_products_title' );

            echo $shortcode_content;

            do_action( 'storefront_homepage_after_featured_products' );

            echo '</section>';

        }
    }
}

}

我认为这是特色产品部分.

I think this runs the Featured Products section.

我尝试更改此代码:

echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';

到:

echo '<h3 class="section-title">' . wp_kses_post( $args['title'] ) . '</h3>';

我将/inc/文件夹上传到我的子目录,并且没有任何更改.我尝试将 storefront-template-functions.php 文件上传到原始店面主题的/inc/文件中.再次,什么也没发生.

I uploaded the /inc/ folder to my child directory, and there were no changes. I tried uploaded the storefront-template-functions.php file into the /inc/ file of the original storefront theme. Again, nothing happened.

我被难住了.我真的以为我有正确的代码可以将这些更改为 h3s.知道我需要做什么才能将特色产品 h2s 更改为 h3s 吗?

I'm stumped. I really thought I had the correct bit of code to change these to h3s. Any idea what I need to do to change the Featured Product h2s into h3s?

推荐答案

好吧,事实证明我看错了地方做了错误的事情.我需要在我的子主题中的 functions.php 文件中添加一些东西才能让它工作.这是我添加的内容:

Well, it turns out that I was looking in the wrong place and doing the wrong thing. I needed to add something to the functions.php file in my child theme to get this to work. Here's what I added:

remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
add_action('woocommerce_shop_loop_item_title', 'abChangeProductsTitle', 10 );
function abChangeProductsTitle() {
echo '<h3 class="woocommerce-loop-product__title">' . get_the_title() . '</h3>';
}

我从这个答案中得到了这段代码的基础:更改woocommerce标题挂钩时,第一项不会更改

I got the basis for this code from this answer: When changing woocommerce title hook the first item doesn't change

这篇关于我如何更改产品 &lt;h2&gt;在 Woocommerce Storefront 到 &lt;h3&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆