I need to remove the empty p tags

1k Views Asked by At
{{ link_content_override|replace({'<p>':'<span>'})|raw }}

This is my actual twig file in which I have used replace filter to change all the p tags into span tags. But still I am getting empty p tags from drupal. I need to remove those empty p tags. The parent tag for the actual twig file is a heading tag. p tag inside heading tag is not advisable so trying to remove the p tag alone.

Expected HTML:

  <h3>
    <a class="heading__link" href="/rice-products/all">
      <span>Hero
      <span><span style="font-size: 16px; line-height: 16px;">Banner</span>
      <span>Text
      </span></span></span>
    </a>
   </h3>

But Actual HTML:

   <h3>
    <a class="heading__link" href="/rice-products/all">
       <span>Hero<p></p>
       <span><span style="font-size: 16px; line-height: 16px;">Banner</span><p></p>
       <span>Text<p></p>
       </span></span></span>
     </a>
    </h3>

On using striptags and providing allowable tags we are able to allow only the specified tags inside striptags but in my case I just need to get rid of p tags alone. I am new to twig files. Can someone help me in achieving the solution

0

There are 0 best solutions below