使用方式
使用片段代碼插件方式填入以下代碼或是至主題編輯器→functions.php→填入以下程式碼
在商品標題使用|符號時都自動換行
add_action( 'pre_ping', 'wpsites_disable_self_pingbacks' );
/**
* 統一商品標題
*
* 以 | 作為換行
*/add_filter( 'the_title', 'custom_the_title', 10, 2 );
function custom_the_title( $title, $post_id ){
$post_type = get_post_field( 'post_type', $post_id, true );
if( $post_type == 'product' || $post_type == 'product_variation' )
$title = str_replace( '|', '<br/>', $title ); // we replace '|' by '<br/>':
return $title;
}