Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Created November 28, 2018 15:43
Show Gist options
  • Save rbaty-barr/5309dfeeebd69902e40c9e767110a986 to your computer and use it in GitHub Desktop.
Save rbaty-barr/5309dfeeebd69902e40c9e767110a986 to your computer and use it in GitHub Desktop.
Adding Opengraph tags for umbraco sites...
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
string domain = "http://" + HttpContext.Current.Request.Url.Host;
var canonicalUrl= String.Empty;
var theDescr = Model.Content.HasValue("socialShareDescription") ? Model.Content.GetPropertyValue<string>("socialShareDescription") : Model.Content.GetPropertyValue<string>("metaDescription");
var theTitle = Model.Content.HasValue("socialShareTitle") ? Model.Content.GetPropertyValue<string>("socialShareTitle") : Model.Content.GetPropertyValue<string>("pageHeadging");
var twitterDesc = Model.Content.HasValue("twitterSocialShareDescription") ? Model.Content.GetPropertyValue<string>("twitterSocialShareDescription") : theDescr;
var ultimateDefault = Model.Content.HasValue("defaultSocialMediaShareImage", true) ? Model.Content.GetPropertyValue<string>("defaultSocialMediaShareImage", true) : "6759";
var pubImageDefault = Model.Content.HasValue("publicationDefaultSocialMediaImage", true) ? Model.Content.GetPropertyValue<string>("publicationDefaultSocialMediaImage", true) : ultimateDefault;
var socialImage = Model.Content.HasValue("socialShareImage") ? Model.Content.GetPropertyValue<string>("socialShareImage") : pubImageDefault;
var theImage = domain + Umbraco.TypedMedia(socialImage).Url;
var twitHandle = Model.Content.HasValue("twitterHandle", true) ? Model.Content.GetPropertyValue<string>("twitterHandle", true) : "@segalco";
canonicalUrl = @domain + @CurrentPage.Url;
}
<!-- Google Plus -->
<meta itemprop="name" content="@Umbraco.StripHtml(theTitle)">
<meta itemprop="description" content="@theDescr">
<meta itemprop="image" content="@theImage">
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@twitHandle">
<meta name="twitter:title" content="@Umbraco.StripHtml(theTitle)">
<meta name="twitter:description" content="@Html.Raw(twitterDesc)">
<meta name="twitter:creator" content="@twitHandle">
<meta name="twitter:image" content="@theImage">
<meta name="twitter:player" content="">
<!-- Open Graph General (Facebook & Pinterest) -->
<meta property="og:url" content="@canonicalUrl">
<meta property="og:title" content="@Umbraco.StripHtml(theTitle)">
<meta property="og:description" content="@Html.Raw(theDescr)">
<meta property="og:site_name" content="Segal Consulting">
<meta property="og:image" content="@theImage">
<meta property="fb:admins" content="">
<meta property="fb:app_id" content="">
<meta property="og:type" content="article">
<meta property="og:locale" content="">
<meta property="og:audio" content="">
<meta property="og:video" content="">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment