How to change Hugo's post image
Asked Answered
O

2

6

I want to change hugo's post image.

+++
title = "how to read the book"
draft = false
date = "2017-01-25T21:39:26-06:00"
image = "book.jpg"
+++

Hello World. New Book Review.

I put book.jpg under mywebsite/static/images/ directory. But the post still using the default image.

Any suggestions?

Omdurman answered 30/1, 2017 at 14:42 Comment(1)
The post image is controlled by certain partial in your templates folder. You can identify which partial it is by searching in your website's project's partials folder (try "image"). When you find the "suspect" template, put certain string and see where it shows up on rendered page. When you pinpoint the code responsible for default image rendering, add it to the original question. Until it's done it's not enough info to answer your question.Banka
O
4

I solved this issue by changing image = "book.jpg" to thumbnail = "images/book.jpg"

I followed the official guide from https://gohugo.io/overview/quickstart/ originally. It is very confusing.

Omdurman answered 31/1, 2017 at 14:8 Comment(0)
C
2

If you're using front matter to configure your posts, follow these steps:

  1. In your config.yaml file, make sure the cover parameters are set to not hide images
  cover:
    hidden: false # hide everywhere but not in structured data
    hiddenInList: false # hide on list pages and home
    hiddenInSingle: false # hide on single page
  1. Add the image to the static folder (ex. meteor.png)
  2. In your post's front matter, add the following lines to reference the image
---
title: "Impact Fanatics"
date: 2022-09-27T18:03:38-04:00
draft: false
relative: true
cover: 
  image: /meteor.png
---
Centri answered 27/9, 2022 at 23:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.