Get the attachment URL on single.php
The the_attachment_link returns an HTML link, so use this code: if ( $attachments = get_children( array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => 1, ‘post_status’ => null, ‘post_parent’ => $post->ID ) ) ); foreach ( $attachments as $attachment ) { echo wp_get_attachment_link( $attachment->ID, ” , true, false, ‘Link to image attachment’ ); } Here … Read more