如何将 Woocommerce Storefront 中的产品 <h2> 更改为 <h3>?

Col*_*lin 3 php wordpress woocommerce

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

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

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

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>';

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

我认为这运行了特色产品部分。

我尝试更改此代码:

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

到:

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

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

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

Col*_*lin 9

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

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>';
}
Run Code Online (Sandbox Code Playgroud)

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