Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 08:05
Show Gist options
  • Save ps-team/7cf6d713c52afb37542540a11500fc63 to your computer and use it in GitHub Desktop.
Save ps-team/7cf6d713c52afb37542540a11500fc63 to your computer and use it in GitHub Desktop.
OpenGraph data output - Razor and metadata needed for displaying better Facebook and Twitter share images for each webpage. Just add to a base razor file.
var OpenGraphImage = "https://www.cumbria.police.uk/SiteElements/Images/Facebook-logo.png";
if(CurrentNode.ThumbnailUrl!="") {
OpenGraphImage = "https://www.cumbria.police.uk" + CurrentNode.ThumbnailUrl;
}
CurrentContext.Page.Head.Add("meta", new { property = "og:title", content = CurrentNode.Title });
CurrentContext.Page.Head.Add("meta", new { property = "og:description", content = CurrentNode.Data.Description });
CurrentContext.Page.Head.Add("meta", new { property = "og:image", content = OpenGraphImage });
CurrentContext.Page.Head.Add("meta", new { property = "og:url", content = CurrentNode.FullPath });
CurrentContext.Page.Head.Add("meta", new { property = "og:site_name", content = "Cumbria Constabulary" });
CurrentContext.Page.Head.Add("meta", new { property = "og:type", content = "Article" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment