When I print the content of the post with
{{ post.content }}
It is outputted like:
<p>Lorem ipsum...</p>
How can I remove the <p>
tag when generated. I need it to be removed before JavaScript starts to process the DOM.
When I print the content of the post with
{{ post.content }}
It is outputted like:
<p>Lorem ipsum...</p>
How can I remove the <p>
tag when generated. I need it to be removed before JavaScript starts to process the DOM.
Jekyll automatically wraps content in p
tags. You can remove those tags with a liquid command. Per Jekyll's documentation:
Because Jekyll grabs the first paragraph you will not need to wrap the excerpt in p tags, which is already done for you. These tags can be removed with the following if you’d prefer:
{{ post.excerpt | remove: '<p>' | remove: '</p>' }}
Hope this helps!
` tag wrapping altogether?
– Trevor Apr 19 '16 at 20:42Maybe you could check this answer: Use a <div>
to wrap content
I tried and it does work. Probably there's a better way, but I haven't been able to figure it out yet.
To output whole pages without the <p>
tags, such as to output a .txt or .json file, create a new layout file (e.g. "_layouts/plaintext.html") with this as the entire content:
{{ content | remove: "<p>" | remove: "</p>" }}
Then call the layout in the header of relevant files, like:
---
permalink: sample.json
layout: plaintext
---
You can use strip_html filter. strip_html
filter is removes any HTML tags from a string.
Example: {{ post.content | strip_html }}