Instagram post URL

I have a very simple script which helps me to display IG images on my website and it works great, ideally hope-ever I would like that once clicked the images would link to the actual post page rather than to the image source. Is there any way to have this tweaked?

PS: I know how to get rid of the fancybox in the link – but I don’t know how and where to retrieve the actual post id / link from.

Here my current code:

    <?php

    function rudr_instagram_api_curl_connect( $api_url ){
        $connection_c = curl_init(); // initializing
        curl_setopt( $connection_c, CURLOPT_URL, $api_url ); // API URL to connect
        curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
        curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
        $json_return = curl_exec( $connection_c ); // connect and get json data
        curl_close( $connection_c ); // close connection
        return json_decode( $json_return ); // decode and return
    }

    $access_token = 'my access token ';
    $username = 'my username';
    $user_search = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token);
    // $user_search is an array of objects of all found users
    // we need only the object of the most relevant user - $user_search->data[0]
    // $user_search->data[0]->id - User ID
    // $user_search->data[0]->first_name - User First name
    // $user_search->data[0]->last_name - User Last name
    // $user_search->data[0]->profile_picture - User Profile Picture URL
    $limit = 8;
    $i = 0;
    // $user_search->data[0]->username - Username

    $user_id = $user_search->data[0]->id; // or use string 'self' to get your own media
    $return = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/" . $user_id . "/media/recent?access_token=" . $access_token);

    //var_dump( $return ); // if you want to display everything the function returns

    foreach ($return->data as $post) {
        echo '<a href="' . $post->images->standard_resolution->url . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
    }
    ?>


Source: stackoverflow-php