Scrape images from Instagram

This will likely break at some point. You should definitely store the result as a transient for performance.

function be_instagram_scrape( $user = false ) {

	if( ! $user )

	$insta_source = file_get_contents('' . esc_attr( $user ) );
	$shards = explode('window._sharedData = ', $insta_source);
	$insta_json = explode(';</script>', $shards[1]);
	$data = json_decode($insta_json[0], TRUE);

	$output = [];

	$images = $data['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'];
	foreach( $images as $image_data ) {
		$image = $image_data['node'];

		$output[] = array(
                'description' => $image['edge_media_to_caption']['edges'][0]['node']['text'],
                'link'        => '' . $image['shortcode'],
                'time'        => $image['taken_at_timestamp'],
                'comments'    => $image['edge_media_to_comment']['count'],
                'likes'       => $image['edge_media_preview_like']['count'],
                'thumbnail'   => $image['thumbnail_src'],

	return $output;

Join Our Team at CultivateWP

We design and build high-performance custom WordPress themes for market leading web publishers. We're looking for designers & developers to join our team.

Learn More

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk