In the Ruby programming language blog framework Jekyll, I implemented noindex, canonical, keywords, etc. as search engine optimization and SEO measures with Jekyll liquid, so I’ll introduce the method.
Initially, I was going to implement it with a plugin called jekyll-seo-tag, but I wrote it myself because it has more extensibility and freedom.
jekyll-seo-tag doesn’t seem to have something like hooks in WordPress, so for example, you can specify title=false for the title, but when I looked into it, things like canonical don’t seem to have that.
In other words, you can’t prioritize canonical if it’s specified, and use the default if it’s not specified.
Since SEO meta tags in HTML basically prioritize the first one defined, having multiple definitions is not good. So I implemented it.
I made it work like this.
---
layout: post
title: "test"
date: 2018-01-01 11:00:09 +0900
categories: blog
index: false
follow: true
keywords: hoge,fuga
canonical_url: 'https://example.com/'
---
Features
- Specifying
index: falsemakes it noindex - Specifying
follow: falsemakes it nofollow - Specifying
keywordsallows you to set meta keywords with priority over the default - Specifying
canonical_urlallows you to set it with priority over the default
{% if page.keywords %} {% else %} {% endif %}
{% if page.canonical_url %} {% else %} {% endif %}
By the way, I've also tweaked <code>description</code> a bit. I'm making the title stick to the beginning.