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

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 #%}" />
<meta property="og:title" content="{% CurrentDocument.DocumentName #%}" />
<meta property="og:description" content="{% CurrentDocument.GetValue("BlogPostSummary") #%}" />

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

<!--End Meta Tags-->

Just update this for a page...

0 votesVote for this answer Mark as a Correct answer

Patrick McGinn answered on October 6, 2016 17:17

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

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