vodoraslo.xyz/new-site/public/blog/meta-description-in-hugo/index.html
2023-02-04 22:30:13 +02:00

68 lines
4.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Meta Description in Hugo | vodoraslo</title>
<link rel="canonical" href="https://vodoraslo.xyz/">
<link rel='alternate' type='application/rss+xml' title="vodoraslo RSS" href='/index.xml'>
<link rel='stylesheet' type='text/css' href='/style.css'>
<link rel="icon" href="/favicon.ico">
<meta name="description" content="This step by step guide will show you how to add meta description in your own Hugo site."/>
<meta name="keywords" content="blog">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="index, follow">
<meta charset="utf-8">
</head>
<body>
<main>
<header><h1 id="tag_Meta Description in Hugo">Meta Description in Hugo</h1></header>
<article>
<h1 id="adding-meta-description-in-hugo">Adding meta description in Hugo</h1>
<p>I assume you are using Luke Smith&rsquo;s theme - Lugo, if you are not, you&rsquo;d have to find these files yourself (e.g. search using vscode).</p>
<h2 id="setting-a-global-meta-description">Setting a global meta description</h2>
<ol>
<li>Locate your config.toml or config.yaml file</li>
<li>Add the following line inside it</li>
</ol>
<p>For config.toml</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">params</span>]
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">description</span> = <span style="color:#e6db74">&#34;The global meta description of your website&#34;</span>
</span></span></code></pre></div><p>For config.yaml</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">params</span>:
</span></span><span style="display:flex;"><span> <span style="color:#f92672">description</span>: <span style="color:#ae81ff">The global meta description of your website</span>
</span></span></code></pre></div><p>It won&rsquo;t work just yet because you have to update the <code>baseof.html</code> file.</p>
<h2 id="updating-the-baseofhtml-file">Updating the baseof.html file</h2>
<ol>
<li>Locate baseof.html</li>
<li>Add or change the meta description line with the following</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;description&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;{{ if .Page.Params.description }}{{ .Page.Params.description }}{{ else if .Summary}}{{ .Summary }}{{else}}{{ .Site.Params.description}}{{ end }}&#34;</span>/&gt;
</span></span></code></pre></div><p>And now if you start your Hugo server locally with <code>hugo serve --noHTTPCache</code> and you right click on your page -&gt; View Page Source -&gt; Search for the meta description tag. It should match what you left in the config file.</p>
<h2 id="replacing-the-global-description-with-a-custom-one">Replacing the global description with a custom one</h2>
<ol>
<li>Have a markdown file ready</li>
<li>In the preamble, add</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span><span style="color:#f92672">description</span>: <span style="color:#e6db74">&#34;Your custom description for this page&#34;</span>
</span></span><span style="display:flex;"><span>---
</span></span></code></pre></div><p>Following these steps would guarantee that you have a meta description for everypage with the ability for creating a custom one whenever you need it!</p>
<div id="nextprev">
<a href="/blog/multiple-index-pages-in-hugo/"><div id="prevart">Previous:<br>Multiple Index Pages in Hugo</div></a>
<a href="/blog/recover-lost-anki-streak/"><div id="nextart">Next:<br>Recover Lost Anki Streak</div></a>
</div>
<div style="clear:both" class=taglist>
Tags: [<a id="tag_blog" href="https://vodoraslo.xyz/tags/blog">Blog</a>]
</div>
<br><br>
</article>
</main>
<footer>
<a href="https://vodoraslo.xyz/">Homepage</a><br><br><a href="/index.xml"><img src="/rss.svg" style="max-height:1.5em" alt="RSS Feed" title="Subscribe via RSS for updates."></a>
</footer>
</body>
</html>