the_post_thumbnail
function display the post thumbnail i.e. <img>
tag. You don’t need to use <img>
tag when using this function.
Try this code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="post">
<h2 class="postTitle"><?PHP the_title(); ?></h2>
<?php the_post_thumbnail( 'predefImageSize', ['class' => 'singleMainImg', 'title' => 'Feature image'] ); ?>
<p class="postinfo">Created on <?php the_time('F j, Y ')?> at <?php the_time('g:i a') ?>. <?php echo getPostViews(get_the_ID()); ?></p>
<?php the_content(); ?>
</article>
<?php setPostViews(get_the_ID()); ?>
<?php endwhile;
else: echo '<p> No Content</p>'; endif;
get_footer();
Modified Code:
<?php the_post_thumbnail( 'predefImageSize', ['class' => 'singleMainImg', 'title' => 'Feature Image'] ); ?>
Using the array’s keys and values to populate different attributes.
You can use this to add classes to the post thumbnail.
Source: the_post_thumbnail documentation at developer.wordpress.org