2016-12-04 35 views
2

如何在WooCommerce產品發佈爲短代碼時刪除標題?產品簡碼 - 刪除博客帖子和頁面上的產品標題

[product_page ID = 「99」]

我得到一個雙標題:

  1. 的簡碼的產品中嵌入
  2. 實際的博客文章

我會喜歡在短代碼上禁用標題,並在博客文章中保留標題,但在商店頁面上保留標題。

回答

2

這些頭銜在content_single-product.php WooCommerce模板文件迷上你可以看到如下:

/** 
* woocommerce_single_product_summary hook. 
* 
* @hooked woocommerce_template_single_title - 5 // <=== HERE 
* @hooked woocommerce_template_single_rating - 10 
* @hooked woocommerce_template_single_price - 10 
* @hooked woocommerce_template_single_excerpt - 20 
* @hooked woocommerce_template_single_add_to_cart - 30 
* @hooked woocommerce_template_single_meta - 40 
* @hooked woocommerce_template_single_sharing - 50 
*/ 

如果只從您的博客文章,並移除網頁上的產品頁面的標​​題,從短碼輸出的時候,你會需要在刪除掛鉤中的標題時添加條件。

這裏是功能和測試代碼:

function remove_some_product_titles(){ 
    if(!is_product()){ 
     remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5); 
    } 
} 
add_action('woocommerce_single_product_summary', 'remove_some_product_titles', 4); 

代碼放在您的活動子主題(或主題)的function.php文件。或者也可以在任何插件php文件中使用。

+0

工作正常!但是,我的標題放在縮略圖旁邊(在產品頁面上),是否有任何可能的方法將它放在縮略圖的上方? – SlyMurphy

+0

向你發送了一個請求 – SlyMurphy

0

您可以使用此刪除標題行動:

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5); 

讓我知道它的工作。

相關問題