Mostly Harmless

Mostly about my amusement

Scrape IFTTT Instagram media into WordPress

I’m a photography nut. I love using my DSLR, I’m mad about film cameras and I use Instagram all the time. I’m also a WordPress user and I have a problem with Instagram: the photos are not preserved on my own site. To fix that I installed the amazing DsgnWrks Instagram Importer plugin and I’ve been using it for years.

While testing WordPress 4.6 beta the plugin stopped working for me. I raised a support topic and I am convinced that my setup has changed. I do not doubt that the problem is mine somehow.

I’m not proficient enough to locate where the break is and I really wanted to share my Instagram photos via my blog. So I created another WordPress account on my photo blog and with my IFTTT account I used this “Instagram to Blog” recipe. That worked, but it loaded the image from Instagram and used the IFTTT URL shortner for link.

I really wanted a copy of my photo on my own server.

I know less about IFTTT recipes than I do the plugin. But I do know how to use WordPress actions and filters so I wrote a small plugin to do the following.

  1. Via the publish_post action look in the content for Instagram image sources and extract those URLs. The wp_extract_urls function is made for this.
  2. When found import those into the WordPress Media Library and attach it to the post using media_handle_sideload.
  3. Make that new attached image the featured image for the post.
  4. Look for IFTTT short URLs and expand them using a simple function I wrote.
  5. Once that’s done then publish the post.

You can view the code via this Gist link. I have that saved and activated as a plugin on my photo blog.

This isn’t the ideal approach for me but it works. The IFTTT recipe successfully publishes a post when I submit a photo to my Instagram account. I’m taking that data and scraping images from another web site. Generally speaking that’s not cool but until I find a cleaner way to do it I’ll have to live with it.

2 Comments

  1. I’m currently in the same boat as you with wanting my Instagram photos natively on my WordPress site. Seems like IFTTT should be able to just do this given I can share photos on my phone to the WordPress media library via the mobile app. Is this still the solution you are using? I came across this gallery plugin (https://wordpress.org/plugins/ifttt-instagram-gallery/) that hooks up with IFTTT, however I’m not exactly interested in it’s specific solution. Thanks for your work on this as I may just go this route.

  2. I went back to the Dsnwrks plugin. It just started working for me. 😉

    https://wordpress.org/plugins/dsgnwrks-instagram-importer/

    The cron job doesn’t work but I’m convinced that’s something with my installation.

Leave a Reply

Your email address will not be published.

*

© 2018 Mostly Harmless

Theme by Anders NorenUp ↑