只需創建一個新的函數來處理get_the_content的值(),以獲得唯一的話的最大數量,並在末尾添加了「更多」鏈接:
function custom_single_product_summary(){
$maxWords = 50; // Change this to your preferences
$description = strip_tags(get_the_content()); // Remove HTML to get the plain text
$words = explode(' ', $description);
$trimmedWords = array_slice($words, 0, $maxWords);
$trimmedText = join(' ', $trimmedWords);
if(strlen($trimmedText) < strlen($description)){
$trimmedText .= ' — <a href="' . get_permalink() . '">Read More</a>';
}
echo $trimmedText;
}
然後在原來的使用重寫代碼,你試圖使用:
remove_action('woocommerce_single_product_summary',
'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_single_product_summary', 'custom_single_product_summary', 10);
修訂答: 改變了行動鉤來呼應VALU因爲WooCommerce期望採取行動來打印輸出。
長描述不支持閱讀更多的產品。由於我們在標籤上顯示內容,因此沒有用處。 – Yasir