Skip to main content

How to create second select featured image in add product page in woocommerce


Note:-> Enqueue these file and get from Multiple Post Thumbnails plugin. After getting these files then you can deactivate plugin.

Page in function.php file

function enqueue_files(){


wp_enqueue_script( 'jquery', get_stylesheet_directory_uri() . '/js/jquery.min.js');
wp_enqueue_style( 'custom-elementor-style', get_stylesheet_directory_uri() . '/widgets/custom-elementor-style.css');

 wp_enqueue_script("featured-image-custom", get_stylesheet_directory_uri(). '/js/multi-post-thumbnails-admin.js');
 


}


add_action("wp_enqueue_scripts","enqueue_files");

add_theme_support( 'post-thumbnails' );
add_image_size( 'feature-image', 960, 500, true );



// Define additional "post thumbnails". Relies on MultiPostThumbnails to work
if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(array(
        'label' => '2nd Feature Image',
        'id' => 'feature-image-2',
        'post_type' => 'product'
        )
    );
   

};



get image with this code which i mentioned below.

<?php MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'feature-image-2', NULL); ?>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...