SEO Checks

The SEO checker lets you put in a Url and run specific checks on the page to make sure you are using best practices. It's also part of the SEO Property.

SEO Checker built into the SEO Property

The SEO Checker comes with a number of checks out of the box, but you can easily create your own. Just create a class that implements ISeoCheck

public interface ISeoCheck
{
    string Name { get; }
    Task<SeoCheckResult> Check(string url, HtmlDocument document, Content.Models.Content content);
    int SortOrder { get; }
}

The example below shows the built in H1 checker that checks if the H1 is missing or if you have more than one H1 tag.

public class HeadingOneSeoCheck : ISeoCheck
{
    public string Name => "H1 Checker";
    public Task<SeoCheckResult> Check(string url, HtmlDocument document, Content.Models.Content content)
    {
        var result = new SeoCheckResult(Name);
        var seoItem = new SeoCheckResultItem();

        // Select all H1 elements
        var h1Tags = document.DocumentNode.SelectNodes("//h1");

        if (h1Tags == null || h1Tags.Count == 0)
        {
            seoItem.Status = SeoCheckStatus.Error;
            seoItem.Message = "Page is missing an <h1> heading tag.";
            result.Items.Add(seoItem);
        }
        else if (h1Tags.Count > 1)
        {
            seoItem.Status = SeoCheckStatus.Warning;
            seoItem.Message = $"Page contains multiple <h1> tags ({h1Tags.Count}). Consider reducing to one for better SEO.";
            result.Items.Add(seoItem);
        }


        return Task.FromResult(result);
    }
    
    public int SortOrder => 1;
}

Last updated