Skip Navigation

[Resolved] Resized Image URL – alt text

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 garenM 1 year, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2609257

Hey is there a way to get the alt text from the original image of an image from"URL of a resized version of the image". Is there a way to get the image ID from the origian image of the resized version?

#2609481

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I would like to know first for what image you want to get original image URL? Do you mean you have created a custom image field and you want to just return the URL? If would be great if you share share your custom field setting for your image field and tell me where exactly you would like to display image URL and alt text?

#2609503

Hey I have a custom image field eg [types field='gallery-images' width='1500' height='1161' separator=',' url='true'][/types] and I need to take the alt text for the image but returns null as its not the original image. Is there a way to get the alt text from that? Can you please advise

#2609551

Hey I have a custom field wpcf-gallery-images and I need the custom size url of the image which is this [types field='gallery-images' width='1500' height='1161' url='true'][/types] and I need to use it on <img src="[types field='gallery-images' width='1500' height='1161' url='true'][/types]" alt="I need the alt text from the image"/>. Please advise?

#2609557

Minesh
Supporter

Languages: English (English )

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

You will have to use the custom shortcode to get alt text of image.

For example, please try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

function get_image_alt_func( $atts ){
  global $post;
     
  $args = array(
  'posts_per_page'   => -1,
  'post_type'        => 'attachment',
  'post_parent'      => $post->ID,
  );
  $attachments = get_posts( $args ); // get attached image
 
  if ( $attachments ) {
    $alt_text = get_post_meta( $attachments[0]->ID, '_wp_attachment_image_alt', true);
  }
    return $alt_text;
}
add_shortcode( 'get-image-alt', 'get_image_alt_func' );

To be able to use this shortcode with your Types shortcodes you need to register it in Toolset > Settings > Front-end content.

For example;

 [types field='gallery-images' width='1500' height='1161' separator=',' url='true' alt="[get-image-alt]"][/types]  

Can you please check if above solution help you to resolve your issue.

#2609593

My issue is resolved now. Thank you!