Skip Navigation

[Resolved] Output just the ALT tag for a repeating image field in Views when URL=’true’

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

Problem:
Output just the ALT attribute tag for a repeating image field in Views when URL='true'

Solution:
To get the alt attribute and display it for repeating image field you will have to add custom shortcode.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/output-just-the-alt-tag-for-a-repeating-image-field-in-views-when-urltrue/#post-2296543

Relevant Documentation:

This support ticket is created 2 years, 10 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by BD 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2295637

BD

I have a repeating image field that I have inserted into a carousel slider in a View. I am calling the image via an intermediate post type.

Everything works fine except the ability to extract the ALT tag from the image which I need to use for the image caption, set by: data-caption="ALT Tag value should go here".

I tried inserting %%ALT%% but this only works if the image is not output as a raw URL.

Here's the View code:

<div class="screenshot-carousel">	    
[wpv-for-each field="wpcf-screenshot-carousel-image" item="@content-panel-page.parent"]<div class="screenshot-image"><img alt="ALT Tag value should go here" src="[types field='screenshot-carousel-image' size='thumbnail' url='true' item="@content-panel-page.parent"][/types]" data-caption="ALT Tag value should go here"/></div><!-- screenshot-image -->[/wpv-for-each]
 </div><!-- screenshot-carousel -->

I have trawled through the support tickets that touch on this issue, but cannot find a solution.

#2296167

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The alt tag will work when you try to output the image and that is how it works.

To display the alt text for your image, you will have to add custom shortcode. Here is the related ticket where shorcode with example is mentioned and you should try to follow that. You should make changes to shortcode as required. Please get in touch with me if you will require further assistance.
- https://toolset.com/forums/topic/alt-text-output-for-images-from-custom-field/#post-1857657

#2296485

BD

Hi Minesh, Thanks very much for your help.

The solution you've linked to works perfectly for single images. However, I am outputting a repeatable image field - so this solution doesn't quite work - it outputs the alt tag of one of the images and applies the same ALT to all images.

Is there a way to adapt this solution to work with repeating images? It's a shame that this request didn't become a built-in feature.

Regards, Nick

#2296509

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where you want to display the alt text and admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2296543

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the following code to "Custom Code" section offered by Toolset:
- hidden link

add_shortcode('img-alt', 'func_repeating_alt_text');
function func_repeating_alt_text($atts = array()) {
global $post, $wpdb;
  
$img_url = $atts['img_url'];

$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $img_url )); 
$attachment_id = $attachment[0]; 
 
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
 
return $alt;
}

I've call it as given under:

[img-alt img_url='[types field='screenshot-carousel-image'  url='true' item='@content-panel-page.parent'][/types]']

Can you please confirm it works as expected.

Regarding the feature request, you can always file a new feature request using the following form:
- https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#2296555

BD

Excellent - that works fine, thanks Minesh,

Nick