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;
}

Feature Image Code in WordPress

Output

Thumbnail Feature Image WordPress

About Raka Rocks

Hi, My self Raka Rocks. I am web designer and Front End Developer total 8 year exp. in this fields. I am a continuous blogger and has blogged on different topics. He loves to surf the Internet and always tries to get new ideas about new technologies and innovations and share this excellent information with all technology lovers.

Leave a Reply

Your email address will not be published. Required fields are marked *