How to get the first image from a WordPress post and display it on your website

If you work with WordPress a lot you may come to a point in time where you need to retrieve the first bullet in a list or the first image from your post and display it somewhere on your site. Luckily, there’s a simple way to do this… check it out!

Add this Function to Functions.php

Display the Image

Get First Bullet in an Unordered List

Regular expressions make it possible to retrieve the first bullet item in an unordered list very easy. See the following example:

You can see that there’s a couple of lines of code commented out above. If you are having problems figuring out the function uncomment the lines to get more information.

Display the List Item:

Using the functions above have come in handy for retrieving data from post in WordPress. I orginally got the code from LiveXP.net, thanks guys!

Devin Walker is a San Diego-based WordPress Developer and enthusiast. He is the author of several popular and highly-rated WordPress themes and plugins. In his free time he enjoys playing Golf and traveling.

Follow Devin: