Remove empty P tags from HTML?

Louis_Walch
Shopify Partner
12 0 2

I am trying to strip empty `<P>` tags from a block of HTML within a Shopify theme. For some reason the `remove` filter is not detecting whatever the space character is inside the tag. I've even tried copy/pasting from source code into my command and it's not working.

{{ article.content | remove: '<p> </p>' | remove: '<p>&nbsp;</p>' }}

 With this, it still remains:

 

Screen Shot 2021-06-13 at 8.32.57 PM.png

0 Likes

Did you have luck with replace?

In addition, are these tags for sure coming from the article or is there a chance they could be being dynamically injected?

◦ Product page slider & thumbnails with swiping for free themes: Minimal | Debut | Brooklyn | Supply
◦ Replace apps with simple copy/paste code snippets. Examples clicking here.
0 Likes
Louis_Walch
Shopify Partner
12 0 2

Thanks for the reply. Yes I have tried `replace` as well. I even tried replacing all space characters with something else and the `<p> </p>` remained in the raw HTML output. It seems to be some kind of other space character but everything I try can't strip it out.

0 Likes

For the sake of testing, are you able to stripe out only the <p>?

◦ Product page slider & thumbnails with swiping for free themes: Minimal | Debut | Brooklyn | Supply
◦ Replace apps with simple copy/paste code snippets. Examples clicking here.
0 Likes
Louis_Walch
Shopify Partner
12 0 2

Yes I can. But I can not strip out whatever Shopify thinks `<p> </p>` is.

0 Likes
LitExtension
Shopify Partner
1210 155 216

Hi @Louis_Walch,

You can try with code: {{ article.content | remove: '<p></p>'}}

Or the best way, go to the articles, edit each HTML of the content, it's the best way: https://i.imgur.com/ZN2ODqB.png

Hope it helps!

LitExtension - Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes
Louis_Walch
Shopify Partner
12 0 2

I ended up cleaning it up with Javascript. Maybe not the best solution but liquid just seemed to limited and was not cooperating.

If anyone needs it:

`.replace( /&nbsp;/g,'' ).replace(/<p><\/p>/gi, '').replace(/<div><\/div>/gi, '')`

0 Likes