Skip to content

Instantly share code, notes, and snippets.

@edirpedro
Last active July 18, 2023 17:07
Show Gist options
  • Save edirpedro/503db5c96faf9e1c45c063d59daac212 to your computer and use it in GitHub Desktop.
Save edirpedro/503db5c96faf9e1c45c063d59daac212 to your computer and use it in GitHub Desktop.
Function to get Instagram feed and cache it on WordPress
/*
* WP Instagram Feed
*
* To get a new Access Token, change the [], put it in the browser and it will return with your token in the next URL.
* https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID]&redirect_uri=[REDIRECT_URL]&response_type=token
*********************************************************************/
function wp_instagram_feed($count = 20) {
$slug = "instagram_feed_self";
$access_token = '[ACCESS_TOKEN_HERE]';
if(false === ($feed = get_transient($slug))) {
$url = "https://api.instagram.com/v1/users/self/media/recent/?count=$count&access_token=$access_token";
$response = wp_remote_get($url);
$feed = json_decode($response['body']);
set_transient($slug, $feed, HOUR_IN_SECONDS);
}
return $feed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment