I’m new to Hugo and don’t know anything about Go, so I’m kind of at a loss here as to why the image doesn’t show up in the header and subsequently not when I test it via the Twitter Card Validator.
This has to be a theme issue, and not a Hugo issue as such. I’ve found direct Twitter meta tags in the theme files — which probably explains why there are problems here — Weird that it only surfaces once I tell ut to add an image though.
I’ll have to investigate this further, thanks so far!
Ok, found a workaround (which works for me at least). I added this to the theme header in themes/hugo-bootstrap-premium/layouts/partials/base/metas.html, as it didn’t have a meta tag for twitter:image at all (it had for other things twitter card thing though, content="{{ .Title }} etc.)
And hey, it works. Why it does’t work when use Params.twitter.image or just Params.Image is beyond me, but at least now the Twitter card works as it should, with the image.
Hmmm. I also have problems with Twitter cards. Here’s an example post from my Hugo blog and here’s the tweet that features it. It looks like Twitter cards aren’t working at all but in the posts’s HTML source you can find the Twitter card section. What am I missing?
And of course: I don’t want to add all the front matter to every post over and over again. I don’t want to add any front matter but instead every post should be Twitter-Cards-friendly. Like: always take the first image from the post as the Twitter Card image. Or: because I already have an image variable in my front matter (it’s used for the blog’s index.html page; one of my own theme modifications) use that for the Twitter Card, too. Is that possible?
I’m using the Hyde-Hyde theme with a few self-made modifications …
Okay, I found this in the official Hugo docs about configuring Twitter cards.
Apparently, you don’t have to add any new partials and can use the internal Twitter cards template by defining the appropriate variables in your site’s config file and a post’s front matter.
Works.
HOWEVER … the two meta datas twitter:site and twitter.creator don’t get rendered into the (public) html files.
Is this something that could be added in a future Hugo release, please?
If you look at the twitter_cards template implementation, you will see that you need to populate some configuration (which isn’t really well documented). In your config.toml (for example), add your Social handles:
For twitter:creator, you need to populate an Authors configuration, where each author would have a twitter property. Again, not well documented, but I stumbled across it with Google. Check the forums or github issues – it will pop up.