• Home
  • About
  • Link
  • Tags
  • Categories

Social media metadata in hexo

Andrew Van Dam On 2020-01-02

Having a random thumbnail image in a hexo post is a pain. Especially with linked in, it would pick up my banner image in a preview then choose any other .jpg image when posting. Almost always my banner image is the one I want shared to socials. So fixing this was a bit of a priority as sharing is the whole point of having this blog! THankfully it seems as though editing Hexo themes is not a complete nightmare if you are just adding Metadata tags. In this instance we want to add the following tags

1
<meta property="og:image" content="http://mysite.com/images/mybannerimage">
2
<meta property="og:title" content="my post title">
3
<meta property="og:description" content="my post description">

To do this, in Hexo i modified my themes\myTheme\layout\layout.ejs file adding the following lines

1
<% if ((is_post())) { %>
2
  <meta property="og:image" content="<%= config.url %><%= page.cover%>">
3
  <meta property="og:title" content="<%= page.title%>">
4
  <meta property="og:description" content="<%= page.description%>">
5
<% } %>

Too easy… I expect any other variables from a post could be included using the page.xxxx tagging structure

One final suggestion.. when testing, ensure that the social media platform is not using cached information by loading fresh each time from http://mysite.com/somepost?n=RandomNumberHere

  • #hexo
  • #social
  • #themes
Newer

CNC Wiring

Older

Serverless blog migration

© 2020 Andrew Van Dam

Powered by Hexo Theme - flex-block

Hosted on