What happened?
Summary
Google Search console reports structured data issues on any pages where I've used tags
in the front matter. This is likely due to an additional comma in a JSON array structure for keywords generated as part of the linked data structure on the page.
I removed the tags on the pages, re-generated the site, submitted the sitemap again to Google Search Console, waited for re-indexing, and the issue is reported resolved. I also tested the page via rich results test, and the issue is resolved too.
This is a temporary fix only - I'd like to be able to add tags to pages.
Reproduce
Generate a new post using hugo new blog/my-post.md
, and add tags to the page front matter.
---
title: "My Post"
date: 2022-01-03T15:46:51+11:00
author: "Jonny"
tags: ["cereal", "milk", "toast"]
---
Generate the site using hugo
, and publish the page to your website. Test it via Google's [rich result test]( (https://search.google.com/test/rich-results). The issue will be reported in the rich result test. You can also have your site re-crawled, and the issue will be reported to you via email
Hugo output
I checked the HTML generated via hugo
command at public/blog/my-post/index.html
- the JSON linked data structure is:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"articleSection": "Blogs",
"name": "My Post",
"headline": "My Post",
"description": "",
"inLanguage": "en-AU",
"author" : {
"@type": "Person",
"name": " Jonathan Sagorin"
},
"creator" : {
"@type": "Person",
"name": " Jonathan Sagorin"
},
"copyrightHolder": " Jonathan Sagorin",
"copyrightYear": "2022",
"dateCreated": "2022-01-03T15:46:51\u002b11:00",
"datePublished": "2022-01-03T15:46:51\u002b11:00",
"dateModified": "2022-01-03T15:46:51\u002b11:00",
"url" : "https:\/\/sagorin.org\/blog\/my-post\/",
"wordCount": "0",
"keywords": ["cereal","milk","toast",]
}
</script>
It looks like the keywords
tag is generating an extra comma in the array, regardless of its position in the array, which is likely the cause of the issue reported by Google Search Console.
"keywords": ["cereal","milk","toast",]
I checked out the source code for Congo, and narrowed it down to themes/congo/layouts/partials/schema.html
, line 37
"keywords": [{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}]
The comma is added regardless of the element in the array.
I was able to reproduce the issue using the exampleSite content too in the Congo theme.
Suggested fix
Add logic to check if the current element is the last element of the array, do not append comma. Similar to what the delimit function does. Possibly use the delimit function, but prepend each element with a double quote? I'm not familiar enough with Go/Hugo, but it would possibly look something like:
{{ with .Params.tags }}{{ delimit . ","}}{{ end }}
. Just needs a double quote now! :)
Reference links
https://support.google.com/webmasters/answer/9166415#error_types
https://search.google.com/test/rich-results
https://gohugo.io/functions/delimit/
Theme version
v1.6.0
Hugo version
hugo v0.86.1+extended darwin/amd64 BuildDate=unknown
What browsers are you seeing the problem on?
Chrome
Relevant Hugo log output
No response