Why is the post thumbnail function not working?

Why is the post thumbnail function not working?

For some reason I can’t get the_post_thumbnail function working. I already added to my functions.php file and yes I did set a featured image and include the_post_thumbnail (); in the loop. What am I doing wrong?

How to add featured image support to your WordPress theme?

The takeaway is that a featured image is a separate field in your WordPress post that allows a theme to do some very interesting and dynamic display options with that image. We can start adding featured image support to our theme by navigating to our functions.php and adding some code to it at the end of the file.

How to add custom themes to functions.php?

That means it needs to be placed directly into functions.php or within a function attached to the ‘after_setup_theme’ hook. For custom post types, you can also add post thumbnails using the register_post_type () function as well. To display thumbnails in themes index.php or single.php or custom templates, use:

Can a featured image be added to a blog post?

Navigating there now does show us that yes, featured images are now enabled in our theme. With our featured image support now in place, let’s go ahead and try adding a featured image to a post on our site.

How do you output a thumbnail in WordPress?

If you want to output the post thumbnail, use the the_post_thumbnail () function. That way you automatically get the image’s alt text, width and height attributes, as well ass srcset and sizes: Thanks for contributing an answer to WordPress Development Stack Exchange!

How to get the URL of a post?

The first argument is which post the get the URL for, while the size is the second argument. But honestly, you shouldn’t be using this function this way. If you want to output the post thumbnail, use the the_post_thumbnail () function. That way you automatically get the image’s alt text, width and height attributes, as well ass srcset and sizes: