Skip to content

Instantly share code, notes, and snippets.

@jenmyers
Last active December 1, 2020 14:34
Show Gist options
  • Save jenmyers/34b2118c2f474dd40a9cf3bc58840948 to your computer and use it in GitHub Desktop.
Save jenmyers/34b2118c2f474dd40a9cf3bc58840948 to your computer and use it in GitHub Desktop.
Meta tags for Twitter cards in a Jekyll site
<!-- Twitter card metatags -->
<!-- Image size option -->
<meta name="twitter:card" content="summary_large_image">
<!-- Twitter username -->
<meta name="twitter:site" content="@twitterusername">
<!-- Page title -->
<meta name="twitter:title" content="{{ page.title }}">
<!-- Page description -->
{% if page.description %}
<meta name="twitter:description" content="{{ page.description }}">
{% else %}
<meta name="twitter:description" content="Default page description">
{% endif %}
<!-- Image path -->
{% if page.image %}
<meta name="twitter:image" content="{{ site.url }}/images/{{ page.image }}">
<meta name="twitter:image:alt" content="{{ page.image-alt }}">
{% else %}
<meta name="twitter:image" content="{{ site.url }}/images/default.png">
<meta name="twitter:image:alt" content="Default image alt text">
{% endif %}
<!-- Compact Twitter card metatags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@twitterusername">
<meta name="twitter:title" content="{{ page.title }}">
<meta name="twitter:description" content="{% if page.description %}{{ page.description }}{% else %}Default page description{% endif %}">
<meta name="twitter:image" content="{% if page.image %}{{ site.url }}/images/{{ page.image }}{% else %}{{ site.url }}/images/default.png{% endif %}">
<meta name="twitter:image:alt" content="{% if page.image-alt %}{{ page.image-alt }}{% else %}Default image alt text{% endif %}">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment