如何在Woocommerce店面中将产品<h2>更改为</h2> <h3>?

时间:2018-06-22 00:43:51

标签: php wordpress woocommerce

我在Woocommerce的Storefront主题中使用了子主题。在主页上,它将特色产品的产品名称呈现为h2s。我想将这些更改为h3(SEO原因)。

h2使用此类: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>';

        }
    }
}

}

我认为这可以运行“特色产品”部分。

我尝试更改此代码:

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 /文件中。同样,什么也没发生。

我很困惑。我真的以为我有正确的代码可以将其更改为h3s。知道我需要做什么才能将特色产品h2更改为h3s吗?

2 个答案:

答案 0 :(得分:3)

好吧,事实证明我在错误的地方看东西,做错了事。我需要在子主题中将一些内容添加到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>';
}

我从以下答案中获得了此代码的基础: When changing woocommerce title hook the first item doesn't change

答案 1 :(得分:0)

可能有很多事情。首先想到的是页面缓存系统,该系统呈现缓存的网页。因此,如果安装了这样的系统,请禁用它。然后,通过单击CTRL + F5,以新鲜的力气查看页面。

如果这不起作用,则可能是CSS中的h2和h3标签具有相同的值。检查CSS,看看是否有h1,h2,h3,h4声明,并查看是否已声明为一个组。如果是,请删除h3并根据需要设置样式。

相关问题