Configuring OpenGraph info & page titles for specific posts

I’m trying to configure the metadata for my website in the front matter of my posts, but it seems to not be being implemented, and I can’t really figure out what to do.

A similar question has been asked previously, I followed the solution for that and was able to get a single OpenGraph implemented site-wide (so Hugo’s drawing from my config file). I then followed the instructions to add OpenGraph info into my front matter, but this isn’t being utilised. Similarly, I’ve noticed that pages outside of my website’s homepage aren’t being titled in my browser’s tabs: so for instance, if I navigate to a blog post then instead we see the full URL rather than the page title. It seems like Hugo’s having a difficult time extracting the relevant bits of data from my front matter and then using that to build my site, but I’m really not sure what the problem is - I’ve played around with various solutions given here for similar problems but to no avail.

Here’s a link to my repository: https://github.com/NickWerren/QC_container/

An example of a post that contains both of the issues mentioned above is the following: https://quantizedcrow.com/posts/old_town_road/old_town_200706/

Thanks in advance for any help!

In this post your generated <title> is empty.

So your code {{ with .Resources.ByType "image" }}{{ range . | first 1 }}{{ .Name | replaceRE ".jpg" "" | humanize | title }}{{ end }}{{ end }}{{ end }} from partial head.html returns a blank string.for this post.

You have to be sure it returns “something”.

For the pages outside of my website’s aren’t being titled in my browser’s tabs this makes no sense to me if it is outside your web site.

Oops, sorry, typo, I meant pages outside of my website’s homepage. So the home page has a title in my tab whereas the page for a post or anywhere else on the website simply has the raw URL as the browser’s tab title.

ah ok. but i already gave you the solution:

 <title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Resources.ByType "image" }}{{ range . | first 1 }}{{ .Name | replaceRE ".jpg" "" | humanize | title }}{{ end }}{{ end }}{{ end }}</title>

2 Likes

That’s excellent, thank you. I’ve managed to fix the problem with tab titles! Although, my issues with metadata remain - there being a sitewide OpenGraph preview rather than specific previews for individual posts.

I think I see my issue, I need to mimic what’s done with the page titles i.e.: extend the code to use any descriptions for the page if they are present, {{else}} just use the “generic” website OpenGraph in my head.html file.

Fixed it by doing the above. Thanks for the help divinerites!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.