Skip Navigation

[Resolved] PDF thumbnails – how to add ALT tags?

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to include the current post's title as the alt text to images, added through a custom shortcode.

Solution:

Suggested to use "wpv-post-title" shortcode, to get the current post's title.

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-title

https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/

https://www.w3schools.com/tags/tag_img.asp

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Alan 5 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1340871

Hi,

I have followed this article to create the function that allows me to use the PDF thumbnail in a View, via a shortcode:
https://toolset.com/forums/topic/how-to-display-thumbnails-of-of-pdfs-uploaded-to-the-types-document-field/

This can be seen on my test site:
hidden link

Each thumbnail image is included within the view by this shortcode:

[getpublicationpdfimg size='medium']

For accessibility reasons, I would like to add the ALT tag to each image, simply using the post title or file name as the alt tag (the PDF file name will be the same as the Post Title in my case, so either could be used.)

Can you please provide a way to achieve this?

Many thanks
Alan

#1341167

Hi Alan,

Thank you for waiting.

To use the current post's title as the "alt" text in the image's thumbnail, you can use the "[wpv-post-title]" shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-title

So, that your code line will change from:


return '<img src=' .$image_src  . ' class="pubdoc-pdf-image"> ';

To:


$post_title = do_shortcode('[wpv-post-title]');

return '<img src=' .$image_src  . ' class="pubdoc-pdf-image" alt="'.$post_title.'"> ';

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1341213

My issue is resolved now. Thank you!