·

photo credit: John P Clare via photopin cc

Create post thumbnails in WordPress with wp_get_image_editor()

So the other day I had to implement a thumbnail of the featured image in WordPress. Little did I know about a little feature in WordPress called wp_get_image_editor, which is basically a tool that allows you to edit an image (resize and crop it), and save it as a new image.


So after a lot of trial and error I came up with the following code to generate and save a 120px thumbnail image of the featured image of a post:

Of course, placing this in a template isn’t very DRY, so I refactored it to this:

In your template you can use it (for example) like this:

So there you have it, enjoy!

Visitors give this article an average rating of 4.2 out of 5.

How would you rate this article?

Leave a Reply