Skip Navigation

[Resolved] Display the title and alt of an image in Content template

This support ticket is created 8 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Beda 8 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#364236

I'm not understanding what I am supposed to put into the Content Template to display the alt and title tags that are associated with the image in the Media Library. The support threads on this seem to point to creating additional custom code. Or is my best solution to create additional fields for Alt and Title? Seems like doubling up what is already in WordPress.
When I use Fields and Views to be able to choose what is in the template, it has Title and Attribute boxes, but I wouldn't know what goes in there.
Can you give me specific instructions on how to add alt and title tags to an image in the Content Template? Right now I have [types field="trainer-headshot" size="medium" align="right" resize="crop"]

#364328

Title and Attribute in the GUI of Toolset for the Image Types Field are the same as in the WordPress Media Editor.
https://toolset.com/documentation/customizing-sites-using-php/functions/#image

I tried a few things locally and I am currently analyzing if this is a Bug or a new feature to add.

The Problem seems, that despite if you add the Title and Att in the WordPress Media Uploader already, it will not be displayed on the View where you use the Types ShortCode, if you do not display it again there.

I will analyze this further also with my 2nd tier.

It is possible that it's either a Bug or a feature to add, and in any case, we would then need to proceed with a Custom Code solution to help you out while we adjust the issue

May I ask you to await my reply tomorrow first thing?

Thank you for your patience.

#364531

OK; as far I see this is not a bug.

See, if you are on a Loop, as in a view, you have many images to output.
We can not know, what you want to output for each Image there.

I mean, if you leave the fields empty in the GUI when inserting the Field, what does that mean?
Doe you want all images empty, or some to fall back to what you set in WordPress, and some not?

On the other hand, what if you want to fill in the fields.
By default then Views will loop each image and just add the infos there, overwriting your previously set things.

That is how loops work, it's not a Bug in Views.

On the other hand, if you set a ALT and caption in WordPress media uploader or when you upload the image to the Types Image Field and insert it DIRECTLY to a single post, you will see, that this info is correct grabbed from the Attachment image info, and displayed.
That's because in this case the GUI is automatically populated with the info you entered earlier, since we are NOT in a loop here, there is no confusion on too many infos.

So, this is a feature request which i filed but I don't yet see an easy way to provide a comprehensive GUI for this.
I am restricted to wait for confirmation from the DEV Team in regard to this.

As for now, what you can do is use Custom PHP and create as example a ShortCode which you use to populate the alt/caption attributes in the Types Image Field ShortCode.
This is custom code, but as a example to start with you can use this below

function image_meta_helper_func( $atts ){
  $post_id = get_the_ID ();
  
  $args = array(
  'posts_per_page'   => -1,
  'post_type'        => 'attachment',
  'post_parent'      => $post_id,
  );
  $the_attachements = get_posts( $args );

  if ($the_attachements){
      foreach ($the_attachements as $the_attachement) {
           $attachment_post = get_post($the_attachement);
           $attachment_id = $attachment_post->ID;
           $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);//Alt text
    }

return $alt;
    
  }
 
}
add_shortcode( 'img-meta', 'image_meta_helper_func' );

Above gets the ALT and returns it so you can dynamically populate the Types ShortCode with it.

Another idea is to simply (if used on Views) fill in the Fields in the GUI.

I apologize that there is no better solution yet.

Thank you

#364532

And of course the simplest is currently to populate the Image with Types ShortCodes.
As example the below:

[types field="image" [types-field='your-alt-filed']" title="[wpv-post-title]" size="full" align="none" class="your class" style="your style"][/types]
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.