In this post, let’s write a custom WordPress function
get_first_image to display the first image from all the posts. We can get this to work with pagination, on a static home page or an independent page. With this method we can retrieve all the first images in each post, including gallery posts. We can also get a default picture for post with no image attached.
Here is my function snippet:
You can use it in
Now all we need to do is call the function in the page template like so:
echo esc_html( get_first_image() ); and style the images or thumbnails.
Please leave a comment below if you know a better way or another method.