Pulling a Blog Post Meta Description

SOLVE
New Contributor

I want to pull a blog post meta descritption for a post listing module I am designing for our homepage. Does anyone know of a way to do this? Or is there a way to  truncate the body content to a certain character count?

 

Here is the module I am building:

 

{% set posts = blog_recent_posts ('default', 3) %}
{% for post in posts %}
<div class="background_focus_image span4 widget-span" style="background:linear-gradient(0deg, rgba(000,000,000,0.5), rgba(000,000,000,0.5)) repeat ,url({{ post.post_list_summary_featured_image }}) no-repeat center bottom; background-size: cover;">
    <div class="homepage_title_backer">
        <h2><a href="{{ post.absolute_url }}">{{ post.name }}</a></h2>
    </div>
    <div class="homepage_desc">
        <p>{{ meta description or truncated contnet would go here }}</p>
    </div>
    <div class="homepage_CTA">
        <a href="{{ post.absolute_url }}" class="hs-button">Read More</a>
    </div>
</div>
{% endfor %}

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Regular Contributor

{{ content.meta_description }}
is the tag to pull the meta description of a page - though if this is on the listing page it might just pull the listing page's description.
 
{{ content.post_body|truncate(25) }}
Will allow you to pull the post body and limit to a certain number of characters. 25 can be switched out to whatever limit you want (max of 255 characters).

 

{{ content.post_summary }} will print the blog post summary - this is what appears before the "read more" separator on your page.

3 Replies 3
HubSpot Moderator

Hi @ahein624    Perhaps @Jsum can provide some guidance here? 

 

Thank you,

Ed Justen


Did my post help answer your query? Help the Community by marking it as a solution
Reply
0 Upvotes
Highlighted
Regular Contributor

{{ content.meta_description }}
is the tag to pull the meta description of a page - though if this is on the listing page it might just pull the listing page's description.
 
{{ content.post_body|truncate(25) }}
Will allow you to pull the post body and limit to a certain number of characters. 25 can be switched out to whatever limit you want (max of 255 characters).

 

{{ content.post_summary }} will print the blog post summary - this is what appears before the "read more" separator on your page.

New Contributor

I'd love to know the if/else statement I can use to amend my blog Listing Template that will print anything entered in the Meta Description field OR use a truncated version of the body content (if nothing is entered in the Meta Description field).

Reply
0 Upvotes