I am using the image render hook from here and it works perfectly with ![Alt inclusion](my-image.jpg)
. I also saw in this forum someone can add an alternate title like this ![Alt inclusion](my-image.jpg "An optional title/caption")
. How do I call that alternate title? I would like to use it as an image caption with different text.
You need to modify the render hook to accept an extra parameter for the title.
I’d strongly advise against setting a title field on an image in addition to alt text, it bad practice and bad for accessibility. If you want a visible text that does not describe the content of the image, which is what alt text is for, use the <figure>
and <figcaption>
elements.
I don’t allow HTML in my markdown posts as a Hugo standard. I just want the title and the caption text to be different. I added a figcaption
at the end of the code in the tutorial with the alt
text as the caption text for now.
<figcaption>
must be a child of a <figure>
element, that is not optional. If you want that, update your render template.
Using the alt value as a caption is pointless as alt text should describe the visual content of an image, e.g.
“A photograph taken during the day time. The image shows groups of people sitting and standing in a field and various. In the middle of the image is a tall stone.”
Such descriptions are not typically what you would want as a caption. If you want captions, use captions.
Again, my point is not to debate what goes or does not. I need a working solution that enables me to have a different alternate text and caption text. Can you provide that?
I already did.
Add a parameter modify your render template to connditionally add the <figure>
and <figcaption
> elements in the event that a caption is passed in using the title syntax in markdown.
This is what I am asking for. You just threw the question back at me. If I knew how to do it, I would. I would prefer to do it this way ![Alt inclusion](my-image.jpg "An optional title/caption")
so [Alt inclusion]
becomes the alternate text and "An optional title/caption"
becomes the caption. If need be, I will disable access of the caption by screen readers.
Apologies, I didn’t understand that you were asking for someone to write code for you.
Please don’t hide captions from screen-readers that’s discrimination and quite possibly illegal.
Found a solution.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.