SEO Optimization for Various Hexo Blog Themes

Published 2023-04-22 02:13 379 words 2 min read

Fix the issue of Hexo theme page description and keywords on-site page keywords; some theme pages lack keywords and description

Fix the issue of missing page descriptions (description) and keywords on HEXO theme pages; some theme pages lack keywords and description

SEO Description and Keywords

description

Full name: <meta name="description" content="我是网站描述">

keywords

Full name: <meta name="keywords" content="我是网站关键词">

To get better indexing and higher weight in search engines, your website needs the above two: description and keywords. If your site is set up but you don't see these two on your blog pages in F12 (DevTools), then you need to fix it or add the code.

Solution

Just add it directly in head.njk and every page on your site will reference it.

Just in case, also add a little bit of logic to head_unique.njk.

You can also change it according to your own situation; it's just for reference.

博客\themes\你的主题\layout\_partials\head\head_unique.njk

markdown escaping rendering issue, this code cannot be posted here

Of course, it's recommended to just download it directly: Click to download reference code

Not recommended

{ %- if page.keywords % You need to delete the -, because of the md escaping issue

{%- if page.keywords %}
<meta name="keywords" content="{{ page.keywords }}" />
{%- elif page.tags and page.tags.length %}
<meta name="keywords" content="{% for tag in page.tags.toArray() %}{{ tag.name }}{% if not loop.last %},{% endif %}{% endfor %}" />
{%- elif theme.keywords %}
<meta name="keywords" content="{{ theme.keywords }}" />
{%- endif %}

The one above is keywords The one below is description

Choose one of the two
Code #1: Absolute positioning
{%-  if page.description %}  
<meta name="description" content="{{page.description}}" />
{%- elif page.description %}
<meta name="description" content="你的网站描述(这是绝对定位)" />
{%- endif %}

Code #2: Configuration positioning
{%-  if page.description %}
<meta name="description" content="{{page.description}}" />
{%- elif page.description %}
<meta name="description" content="{{theme.description}}" />
{%- elif page.description %}
<meta name="description" content="{{config.description}}" />
{%- endif %}

END

[:heart

]{.label .danger} If you don't understand something, feel free to leave your question and I'll help you as soon as I see it.

If you enjoyed this, leave a comment~

... Page views
© 2021 - 2026 Vullfin @VV
Powered by theme astro-koharu · Inspired by Shoka