WordPress: Get Featured Image for Theme or Plugin

When building your own custom theme or plugin for WordPress, you may want to us the get featured image feature to pull in the featured image that is assigned to a particular post. You can specify the exact dimensions that you need for the image or just say thumbnail, medium, large or full and it will call them out based on your default settings.

You can do this on custom themes or plugins, both. So let’s take a look at what it takes.

The first thing you want to do is enable the WordPress get featured images feature by adding the following line into either your functions.php file of your theme or right into the plugin file.

Now you can go ahead and use the WordPress get featured images feature. Anywhere you need to call them just add the following code.

The above code requires the post ID to be able to find the correct image so you either need to stick it inside the loop and use the $post->ID to specify the post ID or you need to replace that with the actual ID. The second parameter ( array(230,170) ) is the size, width first and then height.

It’s a simple little code that will do amazing things for your theme or plugin. Enjoy!

Share this with your friends!
Share on FacebookShare on Google+Tweet about this on TwitterPin on PinterestShare on LinkedIn

No Comments

No comments yet.

Sorry, the comment form is closed at this time.