How to make Get The Image only use embedded images

If you’re a Theme Developer you probably heard of Justin Tadlocks incredible plugin already – for those of you who don’t, let me introduce Get The Image to you.

It’s THE way to extract images from your posts and insert them any way you like in your custom made theme. It does this by checking (in this order)

  • if you have a featured image inserted, or any other custom field defined
  • if not, it’ll see if one is attached to the post
  • if not then it will scan your content for an image embed
  • and if that fails you can display a default image you select

Get The Image will also provide a link to the post when you display the image, or alternatively give you the URL if you want to use it some other way.

I needed an application that displayed only an image that’s embedded in the post.

The Problem: Display the first picture in a post, even if you’ve uploaded it last

Say you write a post, then add a picture to it and review it. Next thing you know is that another picture fits the bill better, so you add that to the post as well. You keep the first one, but show it towards the end of your post. So your first shown picture is technically the last one you’ve uploaded.

By default Get The Image would still display your first uploaded picture, even though that doesn’t represent your post anymore. Let’s see if we can change this to our advantage.

Calling Get The Image

First of all you need to call Get The Image with the scan_image parameter for this feature to become active. You do this like so:

Or, if you’d like to call other parameters, you’d add them like this:

And really, you should be calling it with an “if function exists” statement in case the plugin isn’t activated:

Also, if you’re calling all this from within HTML then it should be wrapped in PHP tags like this:

You get the picture.

But how to we make it ONLY show scanned images?

Even though the feature is now active, Get The Image still looks for a custom field or an attached image by default, and it will always show the one you define with the order_of_image parameter. It defaults to the first picture, but you could set it to any picture you like.

To switch the first two options and make it look for an embedded image straight away (and only) just pass these two parameters:

So your compete statement would look like this:

Hope this helps!

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

4 thoughts on “How to make Get The Image only use embedded images

  1. A user should never directly edit a plugin file. They’ll just lose those changes on the next update of the plugin.

    Plus, the correct instructions for doing what you’re trying to do are included in the plugin’s “readme.html” file.

    1. Hi Justin,

      May I say – what an honour!! You guys at WordPress are my absolute super heroes 😉

      I love your plugin, and believe me I’ve been through the readme file many times. I can’t get it to use the image scan as the first option. Hacking source code is never ideal, but I didn’t see another way.

      Could you point me into the right direction?

      1. Justin,

        You are so right – the answer was right in front of me all along: set attachment and the_post_thumbnail to false and your plugin only uses image_scan if set to true.

        Thank you for the pointer (and for the plugin) 😉

Add your voice!