I am using this code, the best I can write without actually ever seeing an example or one close enough for my brain to understand.
This works, but it could improve. The problem is that I have a custom multicheck and its options are 'post' and/or 'page'. So I am checking the array and creating a variable. There must be another way.
function theme_prefix_featured_image() {
$show = get_theme_mod( 'auto_add_featured_image', array( 'post', 'page' ) );
$size = get_theme_mod( 'featured_image_size' );
if ( ! has_post_thumbnail() || ! is_singular() || empty( $show ) || empty( $size ) ) return;
$post_types = $caption = '';
/// HERE IS THE AREA BEGIN
if ( in_array( 'post', $show ) ) :
$post_types = is_singular( array ( 'post' ) );
endif;
if ( in_array( 'page', $show ) ) :
$post_types = is_singular( array ( 'page' ) );
endif;
if ( in_array( 'post', $show ) && in_array( 'page', $show ) ) :
$post_types = is_singular( array ( 'post', 'page' ) );
endif;
/////// HERE IS THE AREA END
//Get Caption
$caption = get_post( get_post_thumbnail_id() )->post_excerpt;
if ( $post_types ): //// TO CREATE THE CONDITIONAL
if ( ! empty( $caption ) ) :
$caption = sprintf( '<figcaption>%s</figcaption>', $caption );
endif;
$image = genesis_get_image( array(
'format' => 'html',
'size' => $size,
'context' => '',
'attr' => '',
) );
printf( '<figure class="featured-image aligncenter">%s%s</figure>', $image, $caption );
endif;
}
$post_arr=array_intersect(array('post', 'page'), get_theme_mod( 'auto_add_featured_image', array( 'post', 'page' )) );along withif (!empty($post_arr) && is_singular($post_arr)) {....empty($show)but that case is covered with!empty($post_arr).