2020 revision – Still works on WordPress 5.5.1 with WooCommerce 4.4.1
Using this custom function hooked in the_title
filter hook will do the job (replacing a pipe character |
by a <br>
in product titles):
add_filter( 'the_title', 'custom_product_title', 10, 2 );
function custom_product_title( $title, $post_id ){
$post_type = get_post_field( 'post_type', $post_id, true );
if( in_array( $post_type, array( 'product', 'product_variation') ) ) {
$title = str_replace( '|', '<br/>', $title ); // we replace "|" by "<br>"
}
return $title;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Code is tested on Woocommerce 3+ and works.
Now you can target different product pages with the WC conditionals tags as
is_product()
,is_shop()
,is_product_category()
oris_product_tag()
(and many others)…