delarge
3/25/2018 - 10:22 AM

Wordpress featured image tweaks

Move featured image to the top of the sidebar, make it required and add a note. Uses the case-study post type and position is also editable (side/normal - high/normal)

// Feaured image tweaks

function customposttype_image_box() {
    remove_meta_box( 'postimagediv', 'case-study', 'side' );
    add_meta_box('postimagediv', __('Featured image <span style="color:red">*</span>'), 'post_thumbnail_meta_box', 'case-study', 'side', 'high');
}

add_action('do_meta_boxes', 'customposttype_image_box');


function wpse_108013_mandatory_featured_image() {
 if(!has_post_thumbnail()) { // here you check if there's a featured image
      wp_die( 'A featured image is required' ); // there is no featured image
 }
}
add_action( 'pre_post_update', 'wpse_108013_mandatory_featured_image' );

add_filter('admin_post_thumbnail_html', 'add_featured_image_text');
function add_featured_image_text($content) {
    return $content .= '<small style="color:#999">Required</small>';
}