0

Here is a little follow-up to this thread.

So in order to add a line break in Woocommerce Product Titles, I have added this code to the functions.php:

//ADD LINE BREAK  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; }

...which works amazing on Product Category pages. However for some reason it does not when one of the product lists is imported as a widget on a static page (the Front Page of my shop). What could be the problem?

None
  • 1
  • 1
  • perhaps your widget does not include the "|" character? you do need that
    tag in there. what does the innerText or innerHTML look like when rendered as a widget?
    – This Guy Jan 05 '23 at 14:05
  • Can you verify if the `post_type` of your static page is either `product` or `product_variation`? Unless I'm misunderstanding your code, the replacement will only occur there. Try expanding the `if(...)` to include `$post_type == 'post'` if that's what the type of your static page is. – FiddlingAway Jan 05 '23 at 15:01
  • The post_type indeed is 'post', so indeed that makes sense. However no result when I tried to include it in the if, unfortunately. – None Jan 06 '23 at 17:23
  • InnerHTML would look something like this:
    – None Jan 07 '23 at 13:03

0 Answers0