Skip to content

Instantly share code, notes, and snippets.

@spkellydev
Created October 11, 2017 18:39
Show Gist options
  • Save spkellydev/755046d0d0abcd6b6a47789afd371aee to your computer and use it in GitHub Desktop.
Save spkellydev/755046d0d0abcd6b6a47789afd371aee to your computer and use it in GitHub Desktop.
API-free instagram shortcode for last 20 posts
function sl9_instagram_feed($atts, $content = null) {
$atts = shortcode_atts( array(
'account' => null,
'hashtag' => null,
), $atts
);
$json = file_get_contents('https://www.instagram.com/' . $atts['account'] . '/media/');
$instagram_feed_data = json_decode($json, true);
if(is_array($instagram_feed_data['items']) || is_object($instagram_feed_data['items'])) {
foreach ($instagram_feed_data['items'] as $item) {
$link = $item['link'];
$img_url = $item['images']['low_resolution']['url'];
$likes = isset($item['likes']) ? $item['likes']['count'] : '';
$caption = isset($item['caption']) ? $item['caption']['text'] : null;
if ($caption) {
$hashtag = $caption;
preg_match_all("/(#\w+)/", $tweet, $matches);
if ($matches) {
$hashtagsArray = array_count_values($matches[0]);
$hashtags = array_keys($hashtagsArray);
}
}
$dataType = ucfirst($item['type']);
$insta_feed .= '<div class="instagram-post"><a href="' . $link . '" target="_blank" class="instagram-link">
<img class="instagram-image" src="' . $img_url . '"></a>
<div class="instagram-likes">' . $likes . ' People Loved This ' . $dataType . '!</div></div>';
}
}
return do_shortcode($insta_feed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment