Miguel.nz

Add custom HTML to your Featured Image meta box

  October 23, 2015

Sometimes you want custom HTML inside your Featured Image box in WordPress, the one at the right hand side of your screen. You can achieve this with the following action.

add_action( 'add_meta_boxes', 'add_featured_image', 10, 2 );
function add_featured_image( $post_type, $post ) {

    $post_types = get_post_types();

    foreach($post_types as $p ):
    
        //remove original featured image metabox
        remove_meta_box( 'postimagediv', $p, 'side' );

        //add our customized metabox
        add_meta_box( 'postimagediv', 'Featured Image', function($post){
            
            $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );

            // Your HTML Goes here
            echo '<p class="description"><strong>Recommended size</strong>: 800 x 800 pixels min or keep 1:1 as a ratio</p>';

            // Your Image is printed here
            echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );

        }, $p, 'side', 'low');

    endforeach;


}

The code above works for all your post types. You could eventually use this for just one post type, etc.