Lego2012
2/2/2017 - 4:09 PM

Content Example for Page Meta Description

Content Example for Page Meta Description

<!--
That's not something we don't want in the markup. Let's abstract that out!
-->

{% capture page_description %}

{% if page.description %}
  {{ page.description }}
  
{% else if page.excerpt %}
  {{ page.excerpt}}

{% else %}
  {{ site.description }}
{% endif %}

{% endcapture %}

{% assign page_description = page_description | strip_newlines | split: ' ' | join: ' ' | truncate: 160 %}

<meta name="description" content="{{ page_description }}">

<!--
Now, our markup is much more readable and the variable is page_description is reusable.
-->
<meta name="description" content="{{ page_description }}">
<meta property="og:description" content="{{ page_description }}" />
<meta name="twitter:description" content="{{ page_description }}" />
<!--
If placed within the markup, the logic for the meta tag would probably look somethis like this:
-->

<meta name="description" 
  content="{% if page.description %}
    {{ page.description | strip | strip_newlines | truncate: 160}}
  
  {% else if page.excerpt %}
    {{ page.excerpt | strip | strip_newlines | truncate: 160}}
  
  {% else %}
    {{ site.description | strip | strip_newlines | truncate: 160 }}
  
  {% endif %}">