Using Parameters in Your Theme
In Hugo, you can access the parameters specified in the front matter of your content files (e.g., Markdown files) through your Hugo templates. These are called ‘Page-level Params’. This post explores how you can use these within your theme. We’ll be using an example of featured_image added our post below. 1 2 3 4 5 --- title: "My Post" date: 2023-06-01 featured_image: "/img/2022/goldie1.jpg" --- You can then use this parameter when editing your theme using the template tag shown below:
Changing the Syntax Highlighting Style in Hugo
When building a website using Hugo, you might want to customize the syntax highlighting to match your site’s overall aesthetic. Hugo uses Chroma, a powerful syntax highlighting engine, to provide code highlighting out of the box. In this blog post, we’ll guide you through the process of changing the syntax highlighting style in Hugo using Chroma, with the help of the hugo gen chromastyles command.
Add Adsense Ads to Your Posts
This post sets out how you can add your Google Adsense code to your blog posts. As this is MakeWithHugo, we’ll be adding them to our Hugo site. You’ll need a few things before starting, an Adsense account, the snippet of code from Adsense and knowing where you want to put them (or auto ads for the easy option). There’s a few different ways to achieve this, based on where you want them.
Add a 404 Not Found Page
In an ideal world, every web page would exist, but sometimes links go to pages that doen’t exist. This is why we make “404 - not found” pages. In Hugo you can do the same. Many of our sites are hosted with Netlify which also support these files - automatically returning the correct http status code for them. To make yours, you can add a file into your layouts folder.
Using Emoji In Posts & Themes
Emojis have been named word of the year and are seen every day in modern culture. We use them every day on our messaging apps, emails and … err blogs! This post is about how you can enable and use them in both your Hugo themes and, in general, when writing posts. Using Emojis in Themes To use them within your theme, there’s a built in function which turns text in emojis.
Hide a Page in Hugo
Option 1: Draft The simplest way to hide a page when using Hugo is probably to set the post as a draft. This way, you still have the content ready to go for when you need it. To hide a page by setting it as draft, so our drafts page: Set Post as Draft Tutorial Option 2: Hide from Posts List You still want the page to be visible, but you don’t want to show it your blog posts list?
Add Word Count & Estimated Reading Time to Posts
It’s all the trend these days to add “reading time” or a word count on your blog posts to indicate how big they are. We often add a word count as it’s super easy to add to your Hugo site (except we don’t on this site - oops!) Word Count We can use word counts in our theme template. We’ve shown the likely file below, but might change based on your theme and setup.
Show Related Posts in Hugo
Hugo is a great tool for blogging, creating quick and automated posts. As part of a blog, you will sometimes want to show related articles and posts to the one you’re reading. This is what this post sets out to achieve. We can make this in Hugo easily if we are using it’s tags structure. With this in mind, you’ll need to be listing tags within your markdown for this to work.
Add a Last Edited Date to Posts
With frequently changing information it can be useful to record both when a post was created and when it was last updated - showing that it’s been reviewed recently. We do this on this site by showing the created date and showing the last modified date if it’s different from the created date (see above the title). There’s two ways of doing this in Hugo: recording when you last changed it using the last changed date in Git (if you use it) (or a blend of the two)
Syntax Highlighting with Hugo (without JS)
If you are into writing code and use Hugo for building a personal or tech blog - then you’ll want syntax highlighting setup for when you show off your code snippets (like we do on this site!) It is also quite simple when you know how. Some advantages of using this method include not having to download a JS library to do the job (so performance), not having the code flash on load after the JS finishes and not having to manage another library to do a job that’s already included in Hugo.