15

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.

Zentaurus
  • 758
  • 2
  • 11
  • 27
Ali Ismayilov
  • 5,727
  • 2
  • 22
  • 24

5 Answers5

17

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!

ughitsaaron
  • 517
  • 4
  • 10
  • 3
    This seems a little verbose if you have lots of output in a template. Any way to disable the `

    ` tag wrapping altogether?

    – Trevor Apr 19 '16 at 20:42
4

I changed the post file's extension from .md to plain old .html

Ali Ismayilov
  • 5,727
  • 2
  • 22
  • 24
2

Maybe 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.

Community
  • 1
  • 1
Zentaurus
  • 758
  • 2
  • 11
  • 27
2

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
---
Ken Irwin
  • 122
  • 1
  • 9
0

You can use strip_html filter. strip_html filter is removes any HTML tags from a string.

Example: {{ post.content | strip_html }}