0

I referenced this answer

And from that I used this code on my Wordpress Site

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 );
}
return $title;

}

However, when I run it the product title line does indeed break but it leaves the
inside of the product title and customers cannot see that. HTML in Product Title w/ line break

I tried to add this:

< INPUT TYPE="hidden" NAME="
" style="display: none">

To the code snippet but it is not hiding the HTML from the product title. How would I go about inserting the line break and hide the HTML?

Peter Doro
  • 95
  • 1
  • 1
  • 5
  • Having `
    ` in a tiltle is weird, because it mixes identification with styling, in my opinion. Couldn't you work with a sub-title or modify the container width so the title will break by itself?
    – Hans Sep 29 '18 at 13:01
  • I am not sure how to do that @Michael – Peter Doro Oct 01 '18 at 15:04
  • I tested your code and it works fine on a clean WP install. Must be some other code that interferes here, maybe. The `` seems to be html encoded in your example, and the title only breaks because there is no space for the next word. – Hans Oct 01 '18 at 21:51

0 Answers0