Home Forums Front-end Issues Image attributes by default


Image attributes by default

  • Hi!
    First of all sorry, but I read similar post and I didn’t find a solution. How can I do to take ACF fields as image tittle and ALT attribute? I need to take the field “Name” as image tittle and “Name” + “Year” for the ALT attribute. At present I’m using this code to display images:

    $image = get_field('image_12');
    if( !empty($image) ):
    	// vars
    	$url = $image['url'];
    	$title = $image['title'];
    	$alt = $image['alt'];
    	$caption = $image['caption'];
    	// thumbnail
    	$size = 'woocommerce_thumbnail';
    	$thumb = $image['sizes'][ $size ];
    	$width = $image['sizes'][ $size . '-width' ];
    	$height = $image['sizes'][ $size . '-height' ];
    	if( $caption ): ?>
    		<div class="wp-caption">
    	<?php endif; ?>
    	<a href="<?php echo $url; ?>" title="<?php echo $title; ?>">
    		<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
    	<?php if( $caption ): ?>
    			<p class="wp-caption-text"><?php echo $caption; ?>
    	<?php endif; ?>
    <?php endif; ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.