rachelleyen
9/14/2017 - 2:03 AM

Hide Featured Image if the_content has image

detect if a post has at least one image in it. then hide the featured image

<?php $content = $post->post_content;
    $searchimages = '~<img [^>]* />~';
     
    // Run preg_match_all to grab all the images and save the results in $pics
    preg_match_all( $searchimages, $content, $pics );
     
    // Check to see if we have at least 1 image
    $iNumberOfPics = count($pics[0]);
     
    if ( $iNumberOfPics > 0 ) {
         // Your post have one or more images.
    } else {
         the_post_thumbnail();
    }
?>