Create WordPress Thumbnails Automatically

create wordpress thumbnails automaticallyWordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as meta-data. This meta-data can be used by theme authors to do some pretty cool things.

The theme I am currently using allows for a custom field named “thumb”. If you create the “thumb” custom field in a post and pass in the path to an image, for example “wp-content/uploads/2008/12/wordpress_logo.png”, a thumb nail version of the image will appear next the posts title on the home page of my blog. Awesome stuff.

When I discovered this theme and the “thumb” custom field, I already had 225 posts in my blog. I didn’t want to go back and manually create all the custom fields for the existing posts, so I wrote a PHP script to do it for me.

The PHP script cycles through your existing posts and looks for the first image in the post, and creates the thumb field based on it’s location. The script is configurable, your theme may want a different custom field name, like “thumbnail” or “image”.

This code is provided as is. If you aren’t a developer, you should be messing with stuff like this. Be sure to back up your wordpress database before running this.

Instruction:

  • download this code
  • configure the database connection info and custom field name
  • upload this code onto your server
  • point your browser to the file
  • watch the script do it’s magic
  • remove the file from your server
  • donate $2 to my paypal account ([email protected])

Note: This is a one time deal, when you create new posts you will need to add the “thumb” field and image path manually