Title: Title break code
Last modified: December 7, 2023

---

# Title break code

 *  Resolved [SM](https://wordpress.org/support/users/handmadehome/)
 * (@handmadehome)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/title-break-code-2/)
 * Hi,
 * I’m using the code below to line break product titles, and it works fine on archive
   pages: [https://www.shop.handmadehome.me/product-category/sculptures/](https://www.shop.handmadehome.me/product-category/sculptures/)
 * But it doesn’t work in blocks: [https://www.shop.handmadehome.me/](https://www.shop.handmadehome.me/)
 * Can you please help me to fix the code for blocks?
 * Thank you!
 *     ```wp-block-code
       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/><br/>', $title ); // we replace "–" by "<br>"
           }
           return $title;
       }
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ftitle-break-code-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * (@xue28)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/title-break-code-2/#post-17261526)
 * Hi [@handmadehome](https://wordpress.org/support/users/handmadehome/)
 * Thanks for reaching out!
 * The code you’re using is working fine on archive pages because it’s directly 
   affecting the global post object, which is used by WordPress to display posts.
   However, blocks in WooCommerce are rendered differently and they don’t use the
   global post object, that’s why the code doesn’t work there.
 * This is a bit of a complicated topic that would need some customization to address.
   Unfortunately, [custom coding](https://woocommerce.com/support-policy/) is not
   something we can assist with directly. However, I’ll keep this thread open for
   a bit to see if anyone from the community can lend a hand.
 * If you have any other questions related to development or custom coding, don’t
   hesitate to reach out to some of the great resources we have available for support.
   The WooCommerce community is filled with talented open-source developers, and
   many of them are active on the channels listed below:
    - [WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
    - [WooCommerce Advanced Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
    - [WooCommerce Developer Slack Channel](https://woocommerce.com/community-slack/)
    - Hire a [WooCommerce Expert](https://woocommerce.com/experts/)
 * Hope this helps!

Viewing 1 replies (of 1 total)

The topic ‘Title break code’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woo-gutenberg-products-block_71608f.
   svg)
 * [WooCommerce Blocks](https://wordpress.org/plugins/woo-gutenberg-products-block/)
 * [Support Threads](https://wordpress.org/support/plugin/woo-gutenberg-products-block/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-gutenberg-products-block/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-gutenberg-products-block/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-gutenberg-products-block/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/title-break-code-2/#post-17261526)
 * Status: resolved