Snippet to apply schema.org microformats

Google uses microformats to make a better sense of your content is by using microformats. As seen in https://schema.org

At firtst I tried to embed the microformats in the html and css classes, that turned out to be a mess of if statements. Using the JSON-LD format became a more elegant approach, even though it does duplicate some code.

So, this is what I have on my footer.html:

			<script type="application/ld+json">
			{ "@context": "http://schema.org", 
			{{ if .IsHome }}
			"@type": "WebSite",
			{{ else }}
			"@type": "Article",
			{{ end }}

				 "mainEntityOfPage": {
				    "@type": "WebPage",
				    "@id": "{{ .Permalink }}"
				 },
			 "headline": "{{ .Title }}",
			 {{ with .Params.subtitle }}"alternativeHeadline": "{{ . }}",{{ end }}
			 "image": "{{ if .IsHome }}{{ .Site.BaseURL}}images/logo.png{{ else }}{{ with .Params.featured_image }}{{ . | absURL }} {{ else }}{{ with .Params.story_featured_image }}{{ . | absURL }} {{else}}{{ with .Params.images }}{{ range first 1 . }}{{ . | absURL }}{{ end }}{{ else }}{{ .Site.BaseURL }}images/fractal_thumb.png{{ end }}{{ end }}{{ end }}{{ end }}",
			 "author": {
			   "@type": "Person",
			   "name": "CHANGETHISPLEASE"
			 },			 {{ with .Params.tags }}"keywords": "{{ range first 6 . }}{{ . }}{{ end }}",{{ end }} 
			 "wordcount": "{{ .WordCount }}",
			 "publisher": {
			  "@type": "Organization",
			  "name": "CHANGETHISPLEASE",
			  "logo": {
			    "@type": "ImageObject",
			    "url": "CHANGETHISPLEASE-TOSHOWYOURLOGO",
			    "height": 60
			  }
			},
			 "url": "{{ .Site.BaseURL }}",
			 "datePublished": "{{ if not .Date.IsZero }}{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}{{ end }}",
			 "dateCreated": "{{ if not .Date.IsZero }}{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}{{ end }}",
			 "dateModified": "{{ if not .Date.IsZero }}{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}{{ end }}",
			 "description": "{{ if .Params.description }}{{ .Params.description }}{{ else }}{{ .Summary }}{{ end }}",
			 "articleBody": "{{ .Plain  }}"
			 }
			</script>

Change the bits I have hardcoded and should give you a nice boost in structured data. Iā€™m no expert in microformats, so this may require tweaking/correcting.

Hope it helps :slight_smile:

6 Likes