This article shows how to optimise Hugo SEO, including a partial template to check some on-site statistics SEO for your pages.

Hugo SEO plugin: A Search-Engine Optimisation partial template

Peter Prevos

Peter Prevos |

1489 words | 7 minutes

Share this content

Writing articles for a website is fun, but it is even more fun when readers can find your content through their favourite search engine. This article shows how to improve the likelihood that your page will rank highly in search engine results with on-site Search Engine Optimisation (SEO). The Third Hemisphere plugin has several Hugo SEO features to help you optimise the content and architecture of your website.

People are lazy searchers and will rarely go beyond the first page of search results. To improve your chances of a high ranking, your website needs to have:

  • Quality content
  • Good user experience and user interface
  • Flawless security
  • Effective publicity and social media
  • Technical excellence

The last point relates to the architecture of your website and how articles are structured and written. The recommendations in this article are implemented in the Third Hemisphere template, which is used for this website. You can get the source code from GitHub:

Please note that this approach has no guarantees because your ranking on the search results depends on factors you have less control over, such as backlinks. But technical SEO is in your control, so there is no reason to leave your search engine ranking entirely to chance.

This article shows how to optimise Hugo websites to make it easier for search engine bots to crawl your website and analyse your content.

Crawlability

Website bots crawl the internet to analyse websites so that they appear in search results. Crawlability refers to how easy it is for a search engine to find its way around your website. Naturally, you want all your pages to be easily found and index. However, sometimes it is helpful to exclude pages, such as contact forms, from being crawled. There are three locations where your website instructs the search engine bot on what to index.

robots.txt

Search engines that crawl your website first analyse the robots.txt file. This file instructs the search engine which files to include and exclude in its analysis.

Hugo creates a default robots file that allows all pages to be crawled. The Third Hemisphere template enhances this behaviour by adding an exclusion to the robots.txt file for every page where the private variable is set to true.

To generate a custom robots file, set enableRobotsTXT to true in your site configuration.

The robots file also points to the sitemap, which is an index of all your crawlable pages.

Sitemap

Search engines discover new pages by following links. However, a more efficient way for them to find content is by following a sitemap. You can submit your sitemap URL to search engines to assist with crawling.

The sitemap.xml template of the Third Hemisphere theme excludes any pages for which the private variable is set to true.

Canonical URL

A canonical URL lets search engines know that some pages are the same. Duplicate content can hurt your ranking, so you need to tell which page version is canonical.

Each page in the template contains a self-referencing canonical link to indicate that this is the page to be indexed.

<link rel="canonical" href="{{ .Permalink }}" />

Individual pages also can have a robots reference which indicates whether a crawler should index the page and/or follow its links. The head template contains the following line to enable excluding private pages.

<meta name="robots" content={{if eq .Params.private true }}"noindex, nofollow"{{ else }}"index, follow"{{ end }}/>

Structured Data

Structured data helps search engines to classify the webpage it is indexing. It is a bit of JSON in your web page's header that provides metadata to the search engine. The benefit of using correctly formatted structured data is that search engines will better present your page in the search results.

Search engines accept different structured data schemas. The most relevant one for a blog is the article schema. The schema.article.html file in the theme partials contains a schema for website articles, using the metadata for your website and page.

The template uses the following page variables:

  • Page description in the description page variable
  • Page image as the first image defined in the images page variable
  • Published date of the page, or if unavailable, the date that the website is generated
  • The date the page was last modified using the lastmod variable.
  • The name of the author. When not defined in the page, it uses the author defined in the site configuration

Lastly, the template inserts the following site variables:

  • Name of the website (site title)
  • Publisher
  • Logo, as defined in the logo variable (URL to the image)

To optimise the use of structured data, make sure that you define all these site and page variables for all pages.

Content optimisation

Search engines analyse the content of your page using complex algorithms. Unfortunately, there are no formulas to optimise your text, but there are some best-practice rules.

The basic premise of the game is that the text makes frequent references to the search keyword you want the page to rank for. Of course, you cannot outsmart search engines by simply repeating the phrase, but some good practices help to optimise your content.

The Keyword

The keyword (or perhaps better keyphrase) is the term that people enter into their search engine. The central idea of on-site SEO is to optimise the text and structure of your page so that the search engine relates it to that particular phrase.

Several tools are available to research what phrases people commonly use to search for stuff on the internet. Your keyphrase should not be just one word because millions of websites will discuss general topics. A good keyphrase is not too common but is also not too obscure. For example, this page is optimised for the keyword "Hugo SEO".

The keyphrase should be between one and six words. Note that you should only use each keyphrase once on your site so that your pages don't compete with each other.

Slug

In Hugo, the website slug is the same as the filename of your article. You can also set it with the slug page variable. The slug of your page should ideally contain the keyphrase.

Meta description

The meta description is an HTML tag that describes what your page is about. You set the description for each page with the description site variable. The meta description should contain the keyphrase and be between 120 and 155 characters long.

The meta description will also appear in a meta tag in the HTML. If no page description is available, the template either uses the content summary, and if that is unavailable, then the site description.

Ideally, you should also only use unique descriptions for each page on your website.

<meta name="description"
      content="{{ with .Description }}{{ . }}{{ else }}{{ with .Summary }}{{ . }}{{ else }}{{ .Site.Params.description }}{{end }}{{ end }} ">

Page Title

Each page can have two titles, the one displayed on the page in the H1 header and one for the title tag. The Third Hemisphere template allows defining a separate title for the title tag. This is the one that search engines tend to display, while the H1 is what readers see. Use the seotitle variable to create separate titles.

The title needs to be long enough to make sense but short enough to fit into the search engine snippet. The ideal title is between 50 and 60 characters, and it should contain the keyphrase.

Headings

Your content should have headings to guide the reader through your text. At least one header, besides the title, needs to contain the keyphrase.

Text

The content needs to be at least 300 words and contain the keyphrase in the first paragraph. Ideally, the key phrase should be mentioned a few times throughout the text.

Images

All images on your page should all have alt and title tags, one of which should contain the keyphrase.

In the Third Hemisphere template, you can define a featured image with the images parameter. This image should be at least 800 pixels wide with an aspect ratio of 3:2. The image is used in the structured data page summary on list pages. In addition, this image is automatically provided with relevant alt and title tags, using the content of the description page variable.

Hugo SEO Partial Template

The Third Hemisphere Hugo theme contains a partial template that checks the content of each article.

The SEO dashboard only appears when running the site on localhost and when the draft page parameter is true.

Hugo SEO summary for this page
Hugo SEO summary for this page.

You can find the code for this template on the GitHub repository for this theme.

This assessment is pretty crude due to the limited text analysis capabilities in Hugo. Search engines can ignore stopwords, so "SEO for Hugo" is the same as "Hugo SEO". The dashboard is just an aide to guide you when optimising your content.

While all these techniques are considered best practices, there is no substitution for content that readers want to read and share.

Share this content

You might also enjoy reading these articles

Create Bibliographies in Hugo with a shortcode

Create Websites with Emacs: Blogging with Org mode and Hugo

Export WordPress to Hugo Markdown or Org Mode with R