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 );
}
?>