Require a Featured Image in WordPress

The visual aspects of a site are important and many themes depend on the ‘Featured Image’ functionality in WordPress to provide a better visual experience. So, it only makes sense that you may want to consider requiring a featured image before a post can be published.

Here is one way you can do this in WordPress:

This code will make sure a featured image is set before allowing you to publish a post. If a post is already published and there is no featured image, it won’t do anything. This code won’t prevent you from removing a featured image once a post is published.

  1. This is exactly what I’ve been looking for, but sadly I’m not shure how to install it correctly. Can you tell me what I have to do to set it up? Thanks in advance!

    1. Martin,

      The easiest thing to do is to paste the code at the end of your active theme’s functions.php file. The best thing to do is to create a site-specific plugin and put the code there, but if you aren’t familiar with code it probably isn’t feasible.

    1. By default, this function works for all post types that support featured images. If you only want to apply this restriction to a specific post type, just add this check at the beginning of the conditional on line 15: `'{post_type_name}’ === $post_type && `…

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up Next:

Get Attachment ID from a WordPress Image URL

Get Attachment ID from a WordPress Image URL