Support

Account

Home Forums Front-end Issues Image attributes by default

Unread

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:
    THX

    <?php 
    $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; ?>" />
    
    	</a>
    
    	<?php if( $caption ): ?>
    
    			<p class="wp-caption-text"><?php echo $caption; ?>
    
    		</div>
    
    	<?php endif; ?>
    
    <?php endif; ?>
Viewing 1 post (of 1 total)

The topic ‘Image attributes by default’ is closed to new replies.