/**
* Displays a smart post thumbnail. (Version 2.0 - More Robust)
*
* This function first checks for a standard WordPress featured image.
* If not found, it checks for a video thumbnail URL stored in the '_video_thumbnail_url' post meta.
*
* @param string $size The image size to use for the standard thumbnail.
*/
function tsr_display_smart_thumbnail( $size = 'post-thumbnail' ) {
$post_id = get_the_ID();
// Priority 1: Check for a native WordPress featured image.
if ( has_post_thumbnail( $post_id ) ) {
the_post_thumbnail( $size );
return; // Stop here if found.
}
// Priority 2: Check for our custom video thumbnail URL from the plugin.
$video_thumbnail_url = get_post_meta( $post_id, '_video_thumbnail_url', true );
if ( ! empty( $video_thumbnail_url ) ) {
// If a video thumbnail URL is found, output a manual tag.
$alt_text = get_the_title( $post_id ); // Use post title as alt text.
echo '
';
}
// If neither is found, nothing will be displayed.
}