add featured image support wordpress Complete 2022

    By: Manu
    3 years ago

    add featured image support wordpress

    Add below given code inside functions.php. It will enable the featured image support.

         // Add Featured Image support
    
    
        function addFeaturedImageSupport(){
            add_theme_support('post-thumbnails');
        }
    
        add_action('after_setup_theme','addFeaturedImageSupport');
    

    This will add the support for Featured images

    Now edit the post set a featured image and then where ever you want to display the image add this line of code.

    <?php echo get_the_post_thumbnail(); ?>
    

    Image should work. You can pass few arguments in this function read here


    In case you want to add image sizes also


    // Add Featured image Support.
    
    
    
     function addFeaturedImageSupport(){
        add_theme_support('post-thumbnails');
    
        // here we are adding 2 image sizes for different pages.
    
        add_image_size('post-thumbnail', 600,400, true);
        add_image_size('blog-list-page', 250,100, true);
    }
    
    
    add_action('after_setup_theme','addFeaturedImageSupport');