Skip to content

Instantly share code, notes, and snippets.

@clivewalker
Last active December 2, 2015 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clivewalker/ae98b7a47b00d6a4208d to your computer and use it in GitHub Desktop.
Save clivewalker/ae98b7a47b00d6a4208d to your computer and use it in GitHub Desktop.
Perch template for Open Graph data
<meta property="og:site_name" content="<perch:setting id="perch_blog_site_name" />" />
<meta property="og:url" content="<perch:blog id="domain" type="hidden" /><perch:blog id="postURL" type="hidden" />" />
<perch:if exists="og_title"><!--* If Meta and Social tab data available (i.e Post saved), show this *-->
<meta property="og:title" content="<perch:blog id="og_title" label="Social title" type="text" escape="true" />" />
<meta property="og:description" content="<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />" />
<perch:else/><!--* else, show the blog post title and excerpt *-->
<meta property="og:title" content="<perch:blog id="postTitle" type="text" escape="true" />" />
<meta property="og:description" content="<perch:blog id="excerpt" type="textarea" size="s" escape="true" />" />
</perch:if><!--* *-->
<perch:if exists="og_image">
<meta property="og:image" content="<perch:blog id="domain" type="hidden" /><perch:blog id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
</perch:if><!--* *-->
<perch:if exists="og_type"><!--* *-->
<meta property="og:type" content="<perch:blog id="og_type" label="Facebook type" type="select" options="article,book,profile,website,video,music" allowempty="false" />" />
<perch:else/><!--* else, use default article type *-->
<meta property="og:type" content="article" />
</perch:if><!--* *-->
<meta property="article:author" content="Clive Walker" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@horshampubguide" />
<perch:if exists="og_title"><!--* If Meta and Social tab data available (i.e Post saved), show this *-->
<meta name="twitter:title" content="<perch:blog id="og_title" label="Social title" type="text" escape="true" />" />
<meta name="twitter:description" content="<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />" />
<perch:else/><!--* else, show the blog post title and excerpt *-->
<meta name="twitter:title" content="<perch:blog id="postTitle" type="text" escape="true" />" />
<meta name="twitter:description" content="<perch:blog id="excerpt" type="textarea" size="s" escape="true" />" />
</perch:if><!--* *-->
<perch:if exists="og_image">
<meta property="twitter:image" content="<perch:blog id="domain" type="hidden" /><perch:blog id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
</perch:if><!--* *-->
<meta name="twitter:url" content="<perch:blog id="domain" type="hidden" /><perch:blog id="postURL" type="hidden" />" />
@clivewalker
Copy link
Author

This is my Perch Blog meta_head.html template. With Perch Blog 5.0, Open Graph fields are available in the Post edit screen in a Meta and Social tab. This is great for new posts.

For older posts, the fields are populated at edit time but each post must be Saved to create the data and output the field values. This is a real chore if you have a lot of posts. So, in the above, I use a couple of <perch:if> conditionals to use existing data for the older posts.

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