移动产品页面上的标题

Move the title on product pages

我正在尝试将我的产品标题移到顶部(图片上方),但我不确定该怎么做...我希望标题位于产品页面的顶部而不是存档页面。 我花了很长时间研究如何做,但似乎没有任何效果...

有挂钩可以移动吗?也许更改 product_page.php 上的布局?

为了更好地理解产品模板,请参阅默认的 content-single-product。php - https://gist.github.com/dompascal/7825580 and use this visual map - https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/

在您的 functions.php 文件中的活动主题中添加以下内容: 解决方案 #1

//First remove default title
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
//Second add your title in thumbnail section - Keep in mind that title will be below the image bcs of the way this hook works
add_action( 'woocommerce_product_thumbnails', 'woocommerce_template_single_title', 5 );

解决方案#2 另一种方法是将标题放在最上面(取决于您的设计)

//First remove default title
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
//Second add title
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_title', 5 );

解决方案 #3 覆盖主题中的 woocommerce 模板。有很多例子,但这是一个很好的起点 - https://woocommerce.com/document/template-structure/ 此解决方案将为您的模板提供最佳输出,但将来需要更多维护。

如果您使用覆盖这些模板或挂钩的主题,那么您需要使用主题挂钩。但这是每个主题特定的。

第一个解决方案没有用,但它可能与我的主题有关。

即使我换了挂钩,第二种解决方案也很有效:)

回答我的问题:如何将标题移到产品顶部:

//First remove default title
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
//Second add title
add_action( 'woocommerce_before_single_product', 'woocommerce_template_single_title', 5 );