skip to Main Content

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:

Screenshot showing P tags still there after remove

Copy/paste of the pesky tag:

<p> </p>

3

Answers


  1. replace

    Replaces all occurrences of a string with a substring.

    {{ article.content | replace: '<p> </p>', '' }}
    
    Login or Signup to reply.
  2. I think I found something by copying source code from article editor in Sublime Text.
    If you try this (not tested) does it work better?

    {{ article.content | remove: '<p><0xa0></p>' }}
    
    Login or Signup to reply.
  3. You can just hide all empty paragraphs with:

     p:empty {display: none;}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search