[Solved] Fatal error: Call to undefined function the_post_thumbnail() in . . .

Today i was working on a WordPress based website which needed a custom featured posts widget to be created when I received some error.

The widget used this code to get the post thumbnail:

<?php the_post_thumbnail( array(87, 112, true) ); ?>

Let’s not go into much details of this function (you can find it in wordpress codex).

However, when I used this function and refreshed the page using widget, it gave me an error saying:

Fatal error: Call to undefined function the_post_thumbnail() in ****/******/********/*****/***** on line 13

This might seem like a nightmare at first! but relax. This is because you didn’t tell WordPress that your theme is going to use this function to display thumbnails.


To solve the issue of fatal error with the_post_thumbnail() function, simply add this code in your WordPress theme’s functions.php file:


And now this will remove the error from your WordPress blog / site while using this function.

Leave a Reply

Your email address will not be published. Required fields are marked *