I have website I want to create SEO tags for in Umbraco. I was wondering how it is done? are there any best practice documents or advice?
I am not a SEO expert, but hopefully the code snippets below could get you started
On the pages I have added some properties. If you do it by the document type, by inheriting or by compositions you could choose. I have the following properties defined.
Page title, which I aim to have a bit different than the page name. Not sure if it makes any difference - however I hope it will make some more of my focus words for the article either appear in the page title, or the page name. The page name i place in the part, and the page title is used as a part of the article/main content.
Page snippet, which I aim to have as short as possible, and mostly less than 160 characters. The page snippet is used in the article, as well as a summary for metadata.
Page tags, used for metadata keywords as well as for horizontal content navigation on the site.
Featured image, although not strictly a part of SEO, it is important as a part of the strategy to make the content friendly for social media.
Author, might be of importance for SEO, and I have a property for the main author, and as a member property I register facebook profile page.
I have started writing a razor macro, however it needs some more work, however works good for me. I place it as an macro run in the part.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
string domain = "https://" + HttpContext.Current.Request.Url.Host;
string site_name = "sitename";
string og_title = CurrentPage.Name;
string og_image = "";
string og_description = "Description here";
string facebookPageAuthor = "https://www.facebook.com/xx";
string facebookPageSite = "https://www.facebook.com/xx";
string authorName = "asdf";
int authorId = 1099;
string url = domain + CurrentPage.Url;
string facebookAppId = "12341234";
string twitterUserAuthor = "@asdf";
string twitterUserSite = "@qwer";
string logoUrl = domain + "/media/1006/logo.png";
DateTime createDate = CurrentPage.CreateDate;
DateTime updateDate = CurrentPage.UpdateDate;
if (CurrentPage.pageTitle != null && !(CurrentPage.pageTitle is Umbraco.Core.Dynamics.DynamicNull))
{ og_title = CurrentPage.pageTitle;}
@* Check if this page has snippet, and use it exists *@
if (CurrentPage.pageSnippet != null && !(CurrentPage.pageSnippet is Umbraco.Core.Dynamics.DynamicNull))
{ og_description = CurrentPage.pageSnippet; }
@* Check if this page has featured image, and crop to facebook preferred crop size (1200x630px). Use parent page default image it exists *@
if (CurrentPage.featuredImage != null && !(CurrentPage.featuredImage is Umbraco.Core.Dynamics.DynamicNull))
{
var featImage = Umbraco.TypedMedia((int)CurrentPage.featuredImage);
og_image= featImage.GetCropUrl("1200x630"); }
else
{
og_image = Umbraco.Media(CurrentPage.AncestorsOrSelf(1).First().featuredImage).GetCropUrl("1200x630");
}
@* Check if author has facebook page *@
if ((int)CurrentPage.author >0)
{
authorId = (int)CurrentPage.author;
}
var authorModel = Members.GetById(authorId);
authorName = (string)authorModel.Name;
facebookPageAuthor = (string)authorModel.GetProperty("facebookProfilePage").Value;
}
A macro for making a breadcrumb with Microdata is useful for SEO.
@using Umbraco.Web
@using Umbraco.Web.Mvc
@using Umbraco.Core
@using System.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
This snippet makes a breadcrumb of parents using an html ordered list.
It makes metadata available for search engines in the Microdata format.
The CSS is customised for Bootstrap 4
*@
@if (Model.Content.Ancestors().Any())
{
var pageAncestors = Model.Content.Ancestors().OrderBy("Level");
}
I sitemap should be submitted to the search engines. A macro could be something like:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Core.Models
@using Umbraco.Web
@using System.Linq;
@{ Layout = null;
Response.ContentType = "text/xml";
}
@ListChildNodes(Model.Content.AncestorOrSelf(1))
@helper ListChildNodes(IPublishedContent startNode)
{
const int maxLevelForSiteMap = 100;
foreach (var node in startNode.Children.Where(x => Umbraco.MemberHasAccess(x.Id, x.Path)).Where(x => !Umbraco.IsProtected(x.Id, x.Path)).Where(x => x.IsVisible()))
{
if (node.TemplateId > 0)
{
@node.UrlWithDomain()
@(string.Format("{0:s}+00:00", node.UpdateDate))
@{
var freq = node.GetPropertyValue("SearchEngineSitemapChangeFreq");
var pri = node.GetPropertyValue("SearchEngineSitemapPriority");
}
@if (!string.IsNullOrEmpty(freq))
{
@freq
}
@if (!string.IsNullOrEmpty(pri))
{
@pri
}
}
if (node.Level <= maxLevelForSiteMap && node.Children.Any())
{
@ListChildNodes(node)
}
}
}