Skip to content

Instantly share code, notes, and snippets.

Last active June 10, 2024 21:15
Show Gist options
  • Save benbalter/5555369 to your computer and use it in GitHub Desktop.
Save benbalter/5555369 to your computer and use it in GitHub Desktop.
Example of how to use Jekyll's `excerpt` tag.

If your post looked something like:

# Awesome Blog Post

Here is an example post to show how to use the new `excerpt` tag.

The excerpt tag provides a quick and easy way to tease a post by exposing only the first paragraph such as on a blog index page.

Then in your template, you could create an index file like this:

{% for post in site.posts %}
    <a href="{% post.permalink %}">{% post.title %}</a>
    <p>{{ post.excerpt }}</p>
{% endfor %}

Which would produce:

Copy link

I have an image to start off my post, and the excerpt shows only the image. How can I show text and not the image?

Copy link

@vkatariya8 I have the same situation here. My "solution" was put the image at the end of the post.

Copy link

tphbtd commented Oct 4, 2015

@vkatariya8 I have excerpt_separator: "<!--more-->" in my _config.yml. In the post, I then place an image then the first paragraph (the default excerpt) followed by <!--more-->.

Copy link

eonist commented Jan 15, 2016

This didn't work for me either, I had to escape the html more comment inside the liquid expand. Then it worked.

Copy link

rudzainy commented Mar 7, 2016

I believe the excerpt method takes the whole first paragraph if you don't specify the separator.

Copy link

Someone could say me the best excerpt_delimiter for using --- as excerpt delimiter?

Copy link

I use the following

{{ post.content | strip_html | truncatewords:75 }}

Copy link

ghost commented Feb 27, 2017

Thanks @ahmadajmi
If you leave out "strip_html" a post image will show if it is before the truncate.
The following works as well.
{{ post.excerpt | strip_html | truncatewords:75 }}

Copy link

oDinZu commented Oct 30, 2020

I use the following

{{ post.content | strip_html | truncatewords:75 }}

Awesome. I was wondering what would happen if an image was within the post.content excerpt area. I didn't want the image displayed, but only the text. Thanks for sharing! The strip_html did the trick.

Copy link

I have a one sentence paragraph, and a full paragraph below. Any way to set the excerpt to show more than one paragraph and truncate at 275?

Copy link

I have specified excerpt_separator: <!--more--> in the _config.yml file and in front matter, but it doesn't matter where I put it <!–more–>.
Upon request {{ post.excerpt }} I get all content 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment