I recently rebuilt my dog's website. I originally built it in 2016 using WordPress and the Instagram API, as a photo blog to store some photos and watch how much he grew. This time around I wanted something different. I didn't want to use PHP, and since JavaScript frameworks are all the rage I decided to build it using Gatsby. I still wanted to have some sort of CMS so I kept WordPress and am now running it headless. It’s blazing fast. I kept the site design pretty much the same, It’s still powered by the Instagram API, just swapped the tech stack. The Gatsby Front-End is hosted on the Gatsby Cloud and the WordPress CMS is hosted on Hostgator.
Posts get created by a cron job and script on the server. The script will retrieve the Instagram Token from the database. It will then use this token to generate a new one via the Instagram Graph API. The new token gets saved to the database. The script will then hit the Instagram Graph API again this time getting the latest 25 posts. It will then format each Instagram post creation date timestamp into a a date / time string, ex: 12-19-2021_22-10-38-pm. This date / time string will be used as the post's title when saving to WordPress. It will also be used to see if the post already exists in WordPress. If the post does not exist a post will be created and the Image / Video Cover will be attached to the WordPress post. This post creation then triggers a web hook that then triggers a new site build on Gatsby Cloud.
You can view the site at henrythepug.com, the WordPress post creation script will be posted below.
The Config
The Script