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 December 10, 2019 02:30)

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 |(identity)GlobalAdministrator%}

<!--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 December 10, 2019 02:30)

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 December 10, 2019 02:31)

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'" + "/>" |(identity)GlobalAdministrator%}

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.