Example 1 — Get the link for an attachment ID
Pass an attachment ID and echo the URL.
<?php
$link = get_attachment_link( 15 );
echo esc_url( $link ); How It Works
15is the ID of an image in the Media Library.get_attachment_link()returns the page URL as a string.esc_url()makes the URL safe to print.

