Skip Navigation

[Résolu] PDF thumbnails – how to add ALT tags?

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 3 années. 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.

Marqué : ,

This topic contains 2 réponses, has 2 voix.

Last updated by Alan Il y a 3 années.

Assigned support staff: Waqar.

Auteur
Publications
#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

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

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!