Require authors to set featured image for post

前端 未结 3 763
天命终不由人
天命终不由人 2021-01-06 04:29

I have customised my Wordpress site design to use the featured image for posts quite excessively. This is why I need to require all post made by non-admins to require a set

3条回答
  •  滥情空心
    2021-01-06 05:17

    Given Gary's example above, I've written the following to my functions.php file:

    function featured_image_requirement() {
         if(!has_post_thumbnail()) {
              wp_die( 'You forgot to set the featured image. Click the back button on your browser and set it.' ); 
         } 
    }
    add_action( 'pre_post_update', 'featured_image_requirement' );
    

    I'd much rather see this in a plugin as well - there's one called Mandatory Field but it doesn't work with scheduled posts. Both are not really eloquent solutions.

提交回复
热议问题