Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding metadata specific to each post in Jekyll

I've built a blog and would like to add specific meta data to each post in the blog.

At the start of each page I have the following code (simplified to make clear the question I'm asking).

---
layout: default
title:  "Title"
date:   2018-04-19
---

Which goes off and pull in my default.html in _layout

deafault.html

<!DOCTYPE html>
<html lang="en-us">
  {% include head.html %}
  <body>
  </body>
</html>

head.html is where I have the head portion of my website. In there, there is some general header data that I would like on every page. What I'm trying to ask is what is a good way to add page/post specific meta data to each post using Jekyll and liquid (in addition to the general meta data I have already for the overall site)? Where in the flow should I add this page/post specific metadata?

Thanks!

like image 549
sdub0800 Avatar asked Oct 21 '25 04:10

sdub0800


1 Answers

So did some more web searching and was able to find the following. (So all credit to this site for the following code snippets.) Which is the direct answer to my original question, but Andrei did provide a good point (see further below).

https://ehelion.com/blog/2018/02/24/adding-meta-keywords-jekyll.html

Add this to the head.html:

{% if page.keywords %}
<meta name="keywords" content="{{ page.keywords | join: ', ' | escape }}">
{% endif %}

Add this to YAML font matter:

---
layout: post
title:  "Best blog post ever made"
date:   2029-01-01 16:20:00
keywords:
  - some keyword
  - another keyword
  - get rich quick
---

Also thanks to Andrei Gheorghiu for providing that link because it explains that search engines don't really care about the keywords tag anymore. Instead the focus has shifted to meta descriptions. But the same type of code can be applied. Just swap out if page.keywords to if page.description and put a description in the YAML font matter.

like image 88
sdub0800 Avatar answered Oct 22 '25 20:10

sdub0800