Skip to content

Instantly share code, notes, and snippets.

@ofstudio
Created January 6, 2015 13:43
Show Gist options
  • Save ofstudio/01f251538560dbf7ee1a to your computer and use it in GitHub Desktop.
Save ofstudio/01f251538560dbf7ee1a to your computer and use it in GitHub Desktop.
Meta tags snippet for Ghost Themes
{{!-- Tested on Ghost 0.5.7. --}}
{{!-- IMPORTANT! Some things are more likely to work in a different way in future versions of Ghost. Check the documentation --}}
{{#is "index, tag, author"}} {{!-- Meta for index, tag and author contexts --}}
{{#is "index"}}
<title>{{@blog.title}}</title>
<meta name="description" content="{{@blog.description}}"/>
<meta property="og:title" content="{{@blog.title}}"/>
<meta itemprop="name" content="{{@blog.title}}"/>
{{/is}}
{{#is "tag"}}
<title>Posts with tag “{{tag.name}}” — {{@blog.title}}</title>
<meta name="description" content="{{@blog.description}}"/>
<meta property="og:title" content="Posts with tag “{{tag.name}}” — {{@blog.title}}"/>
<meta itemprop="name" content="Posts with tag “{{tag.name}}” — {{@blog.title}}"/>
{{/is}}
{{#is "author"}}
<title>Posts by {{author.name}} — {{@blog.title}}</title>
<meta name="description" content="{{@blog.description}}"/>
<meta property="og:title" content="Posts by {{author.name}} — {{@blog.title}}"/>
<meta itemprop="name" content="Posts by {{author.name}} — {{@blog.title}}"/>
{{/is}}
<meta property="og:type" content="website"/>
<meta property="og:site_name" content="{{@blog.title}}"/>
<meta property="og:url" content="{{@blog.url}}{{{relativeUrl}}}"/>
<meta property="og:description" content="{{@blog.description}}"/>
<meta itemprop="description" content="{{@blog.description}}"/>
{{#if @blog.cover}}
<meta property="og:image" content="{{@blog.url}}{{@blog.cover}}"/>
<link rel="image_src" href="{{@blog.url}}{{@blog.cover}}"/>
<meta itemprop="image" content="{{@blog.url}}{{@blog.cover}}"/>
{{/if}}
{{/is}} {{!-- End of index, tag and author contexts --}}
{{#is "post, page"}} {{!-- Meta for post and page contexts --}}
<title>{{meta_title}} — {{@blog.title}}</title>
<meta itemprop="name" content="{{meta_title}} — {{@blog.title}}"/>
{{#if post.meta_description }}
<meta name="description" content="{{meta_description}}"/>
<meta itemprop="description" content="{{meta_description}}"/>
{{else}}
{{#post}}
<meta name="description" content="{{excerpt words="27"}}…"/>
<meta itemprop="description" content="{{excerpt words="27"}}…"/>
{{/post}}
{{/if}}
{{#post}}
{{#if image}}
<meta property="og:image" content="{{@blog.url}}{{image}}"/>
<link rel="image_src" href="{{@blog.url}}{{image}}"/>
<meta itemprop="image" content="{{@blog.url}}{{image}}"/>
{{else}}
{{#if @blog.cover}}
<meta property="og:image" content="{{@blog.url}}{{@blog.cover}}"/>
<link rel="image_src" href="{{@blog.url}}{{@blog.cover}}"/>
<meta itemprop="image" content="{{@blog.url}}{{@blog.cover}}"/>
{{/if}}
{{/if}}
{{/post}}
{{/is}} {{!-- End of post and page contexts --}}
{{ghost_head}} {{!-- Note: many `og:properties` are generated by ghost_head in post and page contexts --}}
@ofstudio
Copy link
Author

ofstudio commented Jan 6, 2015

partials/meta.hbs

Meta tags snippet for Ghost Themes

Tested on Ghost 0.5.7. IMPORTANT! Some things are more likely to work in a different way in future versions of Ghost. Check Ghost documentation first.

Generates meta tags block like this

<title>TITLE</title>
<meta property="og:title" content="TITLE"/>
<meta itemprop="name" content="TITLE"/>
<meta property="og:type" content="TYPE"/>
<meta property="og:site_name" content="SITE_NAME"/>
<meta property="og:url" content="URL"/>
<meta name="description" content="DESCRIPTION"/>
<meta property="og:description" content="DESCRIPTION"/>
<meta itemprop="description" content="DESCRIPTION"/>
<meta property="og:image" content="IMAGE"/>
<link rel="image_src" href="IMAGE"/>
<meta itemprop="image" content="IMAGE"/>

For index views

  • TITLE{{@blog.title}}
  • DESCRIPTION{{@blog.description}}
  • TYPEwebsite
  • URL{{@blog.url}}{{{relativeUrl}}}
  • SITE_NAME{{@blog.title}}
  • IMAGE{{@blog.url}}{{@blog.cover}} if blog cover exists

For tag views

  • TITLEPosts with tag “{{tag.name}}” — {{@blog.title}}
  • DESCRIPTION{{@blog.description}}
  • TYPEwebsite
  • URL{{@blog.url}}{{{relativeUrl}}}
  • SITE_NAME{{@blog.title}}
  • IMAGE{{@blog.url}}{{@blog.cover}} if blog cover exists

For author views

  • TITLEPosts by {{author.name}} — {{@blog.title}}
  • DESCRIPTION{{@blog.description}}
  • TYPEwebsite
  • URL{{@blog.url}}{{{relativeUrl}}}
  • SITE_NAME{{@blog.title}}
  • IMAGE{{@blog.url}}{{@blog.cover}} if blog cover exists

For post and page views

  • TITLE{{meta_title}} — {{@blog.title}}
  • DESCRIPTION{{meta_description}} if exists meta description. Else {{excerpt words="27"}}…
  • TYPEarticle (generated by {{ghost_head}})
  • URL – post URL (generated by {{ghost_head}})
  • SITE_NAME – blog title (generated by {{ghost_head}})
  • IMAGE{{@blog.url}}{{image}} if post have meta image. Else {{@blog.url}}{{@blog.cover}} if blog cover exists

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