Support

Account

Home Forums Add-ons Flexible Content Field Adding custom field (text) as title of IMAGE

Helping

Adding custom field (text) as title of IMAGE

  • Trying to add the content of sub_field “titel” as title of the image, any idea? this doesn’t work:

    <?php while(the_flexible_field('slider_startseite', 'option')): ?>
    			<?php if(get_row_layout() == 'slide'): // layout: Content ?> 
    				<div>
    					<span>
    
    						<?php 
    							$title = get_sub_field('titel');
    							$image = get_sub_field('bild');
    							$size = 'full'; // (thumbnail, medium, large, full or custom size)
    
    							if( $image ) {
    								echo wp_get_attachment_image( $image, $size, $title );
    							}
    						?>
    
    						<a href="<?php the_sub_field('link'); ?>"><?php the_sub_field('beschreibung'); ?></a>
    					</span>
    				</div>
    			<?php endif; ?>
    		<?php endwhile; ?>
  • Hi @herrfischer

    You can add the title attribute with the functions parameters:

    
    //wp_get_attachment_image( $attachment_id, $size, $icon, $attr );
    <?php 
    	$title = get_sub_field('titel');
    	$image = get_sub_field('bild');
    
    	$size = 'full'; // (thumbnail, medium, large, full or custom size)
    $attr = array(
    'title' =>  esc_attr( $attachment->post_title ),
    );
    
    	if( $image ) {
    	echo wp_get_attachment_image( $attachment_id, $size, 0, $attr );
    	}
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Adding custom field (text) as title of IMAGE’ is closed to new replies.