# Strip specific HTML tags

**URL:** <https://talk.jekyllrb.com/t/strip-specific-html-tags/160>\
**Category:** Help\
**Created:** [February 18, 2017, 9:21pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160 "2017-02-18T21:21:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alehandrof](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/alehandrof/32/74_2.png) [@alehandrof](https://talk.jekyllrb.com/u/alehandrof)\
**Post date:** [February 18, 2017, 9:21pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/1 "2017-02-18T21:21:28Z")

</div>

Can I strip specific HTML tags from a piece of content?

I’d like to display `post.excerpt` but without any images (`img` tags).

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [February 18, 2017, 11:37pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/2 "2017-02-18T23:37:52Z")

</div>

Should be able to do that with the `strip_html` filter.

```auto
{{ post.excerpt | strip_html }}

```

---

<div class="post-metadata">

**Author:** ![alehandrof](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/alehandrof/32/74_2.png) [@alehandrof](https://talk.jekyllrb.com/u/alehandrof)\
**Post date:** [February 24, 2017, 11:10am UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/3 "2017-02-24T11:10:48Z")

</div>

That won’t work in my case. I have something like this:

```auto
<img src="…">
<p>…</p>
<p>…</p>

```

And I’d like it to look like this:

```auto
<p>…</p>
<p>…</p>

```

If I strip the HTML it will combine the two paragraphs.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [February 24, 2017, 4:14pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/4 "2017-02-24T16:14:50Z")

</div>

You’ll likely need a plugin to do this then. There’s the [`remove` filter](https://help.shopify.com/themes/liquid/filters/string-filters#remove) but that’s not going to get you very far.

---

<div class="post-metadata">

**Author:** ![alehandrof](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/alehandrof/32/74_2.png) [@alehandrof](https://talk.jekyllrb.com/u/alehandrof)\
**Post date:** [February 25, 2017, 1:46pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/5 "2017-02-25T13:46:31Z")

</div>

Indeed. That won’t do at all 🙂

---

<div class="post-metadata">

**Author:** ![probablyNikita](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@probablyNikita](https://talk.jekyllrb.com/u/probablyNikita)\
**Post date:** [May 17, 2017, 12:17pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/6 "2017-05-17T12:17:48Z")

</div>

You can use  
`{{ post.excerpt | remove: '<img>' | remove: '<br>' }}`  
for example.

You can take a closer look at this page for docs:

> **[Posts](https://jekyllrb.com/docs/posts/#post-excerpts)**
>
> Blogging is baked into Jekyll. You write blog posts as text files and Jekyll provides everything you need to turn it into a blog.

---

<div class="post-metadata">

**Author:** ![probablyNikita](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@probablyNikita](https://talk.jekyllrb.com/u/probablyNikita)\
**Post date:** [May 17, 2017, 12:20pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/7 "2017-05-17T12:20:21Z")

</div>

Oh you don’t really need to strip line breaks, sorry. Here’s your code:  
`{{ post.excerpt | remove: '<img>' }}`

---

<div class="post-metadata">

**Author:** ![alehandrof](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/alehandrof/32/74_2.png) [@alehandrof](https://talk.jekyllrb.com/u/alehandrof)\
**Post date:** [June 28, 2017, 1:26pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/8 "2017-06-28T13:26:10Z")

</div>

I haven’t tried this out 😊, but my understanding is that the code you suggest will literally remove any text that reads `<img`\>. I don’t have any such text. I have actual image tags, which include `src="…"` and so on.

---

<div class="post-metadata">

**Author:** ![ecupaio](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/ecupaio/32/5868_2.png) [@ecupaio](https://talk.jekyllrb.com/u/ecupaio)\
**Post date:** [December 19, 2019, 5:20pm UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/9 "2019-12-19T17:20:08Z")

</div>

If your original input is in markdown, you can use the markdownify filter to make html, strip all html, then run the markdownify filter so only the paragraphs remain:  
`{{ post.excerpt | markdownify | strip_html | markdownify }}`

---

<div class="post-metadata">

**Author:** ![sandeepv](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sandeepv](https://talk.jekyllrb.com/u/sandeepv)\
**Post date:** [May 7, 2022, 6:51am UTC](https://talk.jekyllrb.com/t/strip-specific-html-tags/160/10 "2022-05-07T06:51:45Z")

</div>

Did this works? I tried not working anyone has new changes that can work
