Support

Account

Home Forums General Issues Changing image URL to Attachment Page URL Reply To: Changing image URL to Attachment Page URL

  • Hi @kandb

    Consider using get_attachment_link(...) which returns the URI of the attachment field. Use the following code:

    get_attachment_link($image['ID']);

    Change your code to the following:

    <?php 
    $images = get_field('photos');
    if( $images ): ?>
    <div id="gallery">
    <h3>Photos</h3>
            <?php foreach( $images as $image ): ?>
    <a class="tooltip" href="<?php echo get_attachment_link($image['ID']); ?>">
        
       <span>
    	<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" /> 
       </span>
    </a>
            <?php endforeach; ?>
    </div>
    <?php endif; ?>