Why isn't the remove filter detecting empty P tags in Shopify?

Louis_Walch
Shopify Partner
13 0 6

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

Replies 6 (6)

diego_ezfy
Shopify Partner
2936 562 883

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?

◦ Follow my blog & youtube for coding tutorials. Most questions in here are already answered there!
◦ Top #4 Shopify Expert, 24h reply. Click here to hire me.
Download copy/paste code snippets that can replace most apps.

Louis_Walch
Shopify Partner
13 0 6

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.

diego_ezfy
Shopify Partner
2936 562 883

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

◦ Follow my blog & youtube for coding tutorials. Most questions in here are already answered there!
◦ Top #4 Shopify Expert, 24h reply. Click here to hire me.
Download copy/paste code snippets that can replace most apps.

Louis_Walch
Shopify Partner
13 0 6

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

LitExtension
Shopify Partner
4860 1001 1133

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
Check out our Shopify migration app to migrate your online store to Shopify

Louis_Walch
Shopify Partner
13 0 6

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, '')`