Skip Navigation

[Fermé] Image ALT tag from media library

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.

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

Last updated by Adriano Il y a 8 années.

Assigned support staff: Adriano.

Auteur
Publications
#188327

Hello,

to display the ALT text set in media library I tried the solution as described here:

https://toolset.com/forums/topic/image-alt-en-title-from-media-library/page/2/#post-186855

I made the additon to function.php and get the image and all other tags correctly. But the ALT tag is replaced by some standard ALT displaying the image file name.

#188359

Dear Daniel,

I need to see the code you have used, can you show me? Please let me know some image showing the field settings as well.

#188628

Hi Adriano,

the functions.php code:

function slider_output($atts) {
extract( shortcode_atts( array(
    'img' => '',
), $atts ) );
   
global $post, $wpdb;
     
$images = get_post_meta($post->ID, $img, false);
$out = '';
foreach ($images as $image) {
$attachment_id = $wpdb->get_var($wpdb->prepare(
"SELECT ID FROM $wpdb->posts WHERE guid = %s",
$image
));
$image_title = get_the_title($attachment_id);
$thumb = wp_get_attachment_image_src( $attachment_id, ('slider-image') );
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$out .= '<img itemprop="image" src="' . $thumb[0]. '" alt="' . $alt . '" />';
}
$out .= '';
return $out;
}
add_shortcode('slider-output', 'slider_output');

I work local so there is no image url I can provide. The view get the image via [slider-output img="wpcf-intro-slider-top"] (image field).
Output is:

<img itemprop="image" src="/cod_black_ops_2_vengeance-710x411.jpg" alt="cod black ops 2 vengeance 710x411 Call of Duty: Black Ops 2"  title="Call of Duty: Black Ops 2" />

So TITLE tag was added on some point and ALT tag was replaced.

#189166

Dear Daniel,

Thank you for provide the code, it looks like fine. Please attach the "cod_black_ops_2_vengeance-710x411.jpg" image settings where can I see the ALT and other fields.

Le sujet ‘[Fermé] Image ALT tag from media library’ est fermé à de nouvelles réponses.