Share:
Without plugins show default featured image or use if else condition to if have post thumbnail then show thumbnail image on post/page feature image and if have not thumbnail post/page images then show default image which you want to show for all pages.
In this article today we learn to how to set feature image in our custom page or post.
In this step we will copy and paste code in your single.php or page.php where we want to use
<?php if ( has_post_thumbnail($r->ID)) {
echo get_the_post_thumbnail($r->ID, array('full'));
}else{
echo '<img src="images/default-image-url.png"/>';
}
?>
Here is final code below just copy and paste this
<section id="inner_banner">
<?php if ( has_post_thumbnail($r->ID)) {
echo get_the_post_thumbnail($r->ID, array('full'));
}else{
echo '<img src="images/default-image-url.png"/>';
}
?>
</section>
Use Some CSS file to manage thumbnail image according to you how to want display on page design. apply code in style.css file
section#inner_banner {
padding: 0;
margin: 0;
overflow: hidden;
margin-top: 80px;
width: 100%;
}
section#inner_banner img {
width: 100%;
height: 380px;
object-fit: cover;
}

Output
