skip to Main Content

Recently, my WordPress site was updated and the Woocommerce product pages are now showing the <br> code in our product titles as text.

Displays: "New <br> Collection" on product page.

In page source, the code is showing as

<h1 class="product_title entry-title">
    New&lt;br&gt;Collection</h1>
<p class="price"></p>

How do I fix this so there is a line break to display the product title as…
"New
Collection"

Thanks in advance.

2

Answers


  1. If you cannot fix it in code then try

    window.addEventListener("load",function() {
      [...document.querySelectorAll(".product_title")].forEach(h => h.innerHTML = h.innerHTML.replace(/&lt;br&gt;/g,"<br/>"))
    })  
    <h1 class="product_title">A split&lt;br&gt;title</h1>
    <h1 class="product_title">A split&lt;br&gt;title</h1>
    Login or Signup to reply.
  2. Solution from @mplungjan is really useful. I waste hours to try to found a PHP solution without success. JS code do not decrease performance at all, the only problem is that in case your DOM loading is slow, the chars could be displayed in page, before script change it. I added it in function.php @mplungjan suggest like below.
    This issue is appeared after WooCommerce plugin upgrade. This happen only in single product page and is not displayed in Titles inside products list page.

    Added it:

    
         /***********************************************************************
         *  CODE FOR line BREAK in the title of woocommerce product
         * 
         ************************************************************************/
             
             function title_br_hook_javascript() {
                 ?>
                     <script>
                       window.addEventListener("load",function() {
               [...document.querySelectorAll(".product_title")].forEach(h => h.innerHTML = h.innerHTML.replace(/&lt;br&gt;/g,"<br/>"));
                          console.log("restore prod's title br");
             }) 
                     </script>
                 <?php
             }
             add_action('wp_head', 'title_br_hook_javascript');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search