Image Macro for Open Graph Tags

Patrick McGinn asked on October 6, 2016 16:22

I'm trying to find a Kentico system macro to populate the "og:image" meta tag. Here's the code I'm currently using:

<meta property="og:image" content="{%CurrentSite.SiteDomainName.GetAbsoluteUrl() + "/getattachment/" + CurrentDocument.MenuItemTeaserImage + CurrentDocument.NodeAliasPath #%}" /> 

If anyone has successfully populated this tag with a Kentico macro, I'd be very interested. If there's not a clean way to do it with macros, we can generate it server-side, but wanted to ask before I came to that conclusion.

Full disclosure, this is for a standard page type, not a News Item or Blog Post. Thanks for any assistance you can provide.

Recent Answers


Brenden Kehren answered on October 6, 2016 16:44

So what's getting generated? Also, where are you using this? Transformation? Layout? Template?

1 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on October 6, 2016 17:00 (last edited on March 24, 2018 12:15)

Here is a recent example of an open graph implementation using macros:

Use the head html webpart:

<!--Meta Tags for OpenGraph-->
<meta property="og:type" content="article" />
<meta property="og:site_name" content="mysite"/>
<meta property="og:url" content="http://mysite.org{% CurrentDocument.NodeAliasPath |(user)zbynekh|(hash)eba1eebcc09e1f1b33bc37a8cfcd6e8268396cc650c4bdf9c08669f653096273%}" />
<meta property="og:title" content="{% CurrentDocument.DocumentName |(user)zbynekh|(hash)ec03a268bc3a3e603ab91db461e05672ca5ee830baa9431c6a277c992317d119%}" />
<meta property="og:description" content="{% CurrentDocument.GetValue("BlogPostSummary") |(user)zbynekh|(hash)9d65e2c010b7378249977c3b9c72defbe36e2da89bf520b8094a8398b72715bd%}" />

{% foreach (attachment in Documents[NodeALiasPath].AllAttachments) {
"<meta property='og:image' content='http://mysite.org/getattachment/" + attachment.AttachmentGUID + "/attachment.aspx'" + "/>";
} |(user)zbynekh|(hash)6fb383661082f9738c06a096e13ba02e29b2da0aca2a3ffeb1a3f84c48ac5e9a%}

<!--End Meta Tags-->

Just update this for a page...

1 votesVote for this answer Mark as a Correct answer

Patrick McGinn answered on October 6, 2016 17:17 (last edited on March 24, 2018 12:15)

Thanks for the quick feedback Brenden and Josh.

Brenden - I'm just dropping the html meta into the

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on October 6, 2016 17:33

I believe for opengraph to work, it needs to be in the head of the web page. I think I read that on opengraphs site.

0 votesVote for this answer Mark as a Correct answer

Ron Rainey answered on November 17, 2017 20:28 (last edited on March 24, 2018 12:16)

I know this is an old thread but is there a way to specify variants when doing this? I have 3 versions of each photo and it randomly grabs whatever loaded last- often giving me the small thumbnail version. This is what I am using- {% "<meta property='og:image' content='http://sitename.com/getattachment/" + CurrentDocument.AllAttachments.FirstItem.AttachmentGUID + "/attachment.aspx'" + "/>" |(user)zbynekh|(hash)05922328ef0a9a5d6ae7db6f3279f898c527c807bbf2406093fcaf137fc9cd3b%}

I tried some of the variant macros to no avail. Is there a way to grab the original or the large file? Our originals are already web scale.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.