{"id":2524,"date":"2025-10-01T10:39:36","date_gmt":"2025-10-01T10:39:36","guid":{"rendered":"https:\/\/www.8theme.com\/documentation\/?post_type=docs&#038;p=2524"},"modified":"2025-10-01T10:44:16","modified_gmt":"2025-10-01T10:44:16","password":"","slug":"display-a-video-as-the-featured-image-on-the-products-archive","status":"publish","type":"docs","link":"https:\/\/www.8theme.com\/documentation\/xstore\/additional-customisation\/display-a-video-as-the-featured-image-on-the-products-archive\/","title":{"rendered":"Display a video as the featured image on the Products Archive"},"content":{"rendered":"\n<p>Adding the code from this article to the child-theme\/functions.php file will display the videos uploaded in the product settings as the featured image on the Products Archive (shop, categories) pages.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('etheme_product_grid_list_product_wrapper_element_attributes', function($attr, $product, $local_settings, $object) {\n\tglobal $show_featured_as_video_data;\n\tif ( !is_array($show_featured_as_video_data) ) \n\t\t$show_featured_as_video_data = array();\n\n\t$product_id = $product->get_id();\n\t$product_video_thumbnail = etheme_get_option('product_video_thumbnail', false);\n\tif ( etheme_get_custom_field('product_video_thumbnail', $product_id) == 'disable' )\n\t    $product_video_thumbnail = false;\n\tif ( !$product_video_thumbnail ) {\n\t\treturn $attr;\n\t}\n\n\t$size = $local_settings&#91;'image_size'] != 'custom' ? $local_settings&#91;'image_size'] : 'woocommerce_thumbnail';\n\n\t$show_featured_as_video_data&#91;$product_id] = array();\n\n\t$video_slides_array = array();\n\t$video_attachments = array();\n\t$video_slides = '';\n\n\t$product_video_attrs = etheme_get_option('product_video_thumbnail_attributes', array('preload', 'loop'));\n    $product_video_pause_on_hover = etheme_get_option('product_video_pause_on_hover', false);\n    $size = $local_settings&#91;'image_size'] != 'custom' ? $local_settings&#91;'image_size'] : 'woocommerce_thumbnail';\n\n\t$show_featured_as_video = false;\n\n\tif ( $product_video_thumbnail ) {\n\t    $videos = etheme_get_attach_video($product_id);\n\t        if (isset($videos&#91;0]) &amp;&amp; $videos&#91;0] != '') {\n\t            $video_attachments = get_posts(array(\n\t                'post_type' => 'attachment',\n\t                'include' => $videos&#91;0]\n\t            ));\n\t            foreach ($video_attachments as $video) {\n\t                if ( !$video || !in_array($video->post_mime_type, array('video\/mp4', 'video\/webm', 'video\/ogg'))) continue;\n\t                $video_slides_array&#91;] = array(\n\t                    'item_type' => 'video',\n\t                    'src' => $video->guid,\n\t                    'type' => str_replace(\n\t                        array('video\/mp4', 'video\/webm', 'video\/ogg'),\n\t                        array(\n\t                            'video\/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"',\n\t                            'video\/webm; codecs=\"vp8, vorbis\"',\n\t                            'video\/ogg; codecs=\"theora, vorbis\"'\n\t                        ),\n\t                        $video->post_mime_type)\n\t                );\n\t            }\n\t        }\n\t    $has_video = count($video_attachments) > 0;\n\n\t    $show_featured_as_video = $has_video || false;\n\t}\n\n\tif ( $show_featured_as_video ) {\n\n\t\tif ( in_array($local_settings&#91;'image_hover_effect'], array('slider'))) {\n\t\t    $video_slides = wp_json_encode(\n\t\t        array(\n\t\t            'items' => array_merge($video_slides_array, array_map(\n\t\t                function ($item_value) {\n\t\t                    return array(\n\t\t                        'item_type' => 'image',\n\t\t                        'src' => $item_value\n\t\t                    );\n\t\t                }, explode(';', $object->etheme_get_image_list($product, true, $size))))\n\t\t        ));\n\t\t}\n\n        $product_video_params = array(\n            'muted=\"muted\"'\n        );\n        if ( in_array('preload', $product_video_attrs))\n            $product_video_params&#91;] = 'preload=\"auto\"';\n        if ( in_array('loop', $product_video_attrs))\n            $product_video_params&#91;] = 'loop=\"true\"';\n        if ( in_array('autoplay', $product_video_attrs)) {\n            $product_video_params&#91;] = 'autoplay=\"true\"';\n            if ($product_video_pause_on_hover)\n                $product_video_params&#91;] = 'data-pause-on-hover=\"true\"';\n        }\n        $video_poster = '';\n        if ( in_array('poster', $product_video_attrs) ) {\n            if ($product->get_image_id()) {\n                $video_poster = wp_get_attachment_image_src($product->get_image_id(), $size, false, array())&#91;0];\n            } elseif ($product->get_parent_id()) {\n                $video_poster = wp_get_attachment_image_src($product->get_parent_id(), $size, false, array())&#91;0];\n            }\n\n            if (!$video_poster) {\n                $video_poster = wc_placeholder_img_src($size, array());\n            }\n\n            if ( $video_poster )\n                $product_video_params&#91;] = 'poster=\"'.$video_poster.'\"';\n        }\n\n        $show_featured_as_video_data&#91;$product_id]&#91;'video_attachments'] = $video_attachments;\n        $show_featured_as_video_data&#91;$product_id]&#91;'product_video_params'] = $product_video_params; \n\n\t\tif (in_array('autoplay', $product_video_attrs) &amp;&amp; $product_video_pause_on_hover ) $attr .= ' data-video-hover-state=\"pause\"';\n\n        else if (!in_array('autoplay', $product_video_attrs)) $attr .= ' data-video-hover-state=\"play\"';\n\n        if ( 'slider' == $local_settings&#91;'image_hover_effect'] ) : $attr .= ' data-videos=\"'. esc_attr($video_slides) . '\"'; endif;\n\n\t}\n\n\treturn $attr;\n}, 10, 4);\nadd_filter('etheme_product_grid_list_product_element_image', function($image, $product, $local_settings) {\n\n\tglobal $show_featured_as_video_data;\n\tif ( !is_array($show_featured_as_video_data) )\n\t\t$show_featured_as_video_data = array();\n\n\t$product_id = $product->get_id();\n\n\tif ( empty($show_featured_as_video_data) || !array_key_exists($product_id, $show_featured_as_video_data)) return $image;\n\n    $size = $local_settings&#91;'image_size'] != 'custom' ? $local_settings&#91;'image_size'] : 'woocommerce_thumbnail';\n\n    $video_sources_shown = 0;\n\t\n\tif ( isset($show_featured_as_video_data&#91;$product_id]&#91;'video_attachments']) &amp;&amp; count( $show_featured_as_video_data&#91;$product_id]&#91;'video_attachments'] ) > 0 ): $video_sources_shown = 0; \n\t\tob_start(); ?>\n\t    &lt;video &lt;?php echo implode(' ', $show_featured_as_video_data&#91;$product_id]&#91;'product_video_params']); ?>>\n\t        &lt;?php foreach ( $show_featured_as_video_data&#91;$product_id]&#91;'video_attachments'] as $video ):\n\t            if ( $video_sources_shown > 0 ) break; ?>\n\t            &lt;?php $video_ogg = $video_mp4 = $video_webm = false; ?>\n\t            &lt;?php if ( $video->post_mime_type == 'video\/mp4' &amp;&amp; ! $video_mp4 ): $video_mp4 = true; ?>\n\t                &lt;source src=\"&lt;?php echo esc_url( $video->guid ); ?>\"\n\t                        type='video\/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'>\n\t            &lt;?php\n\t            $video_sources_shown++;\n\t            endif; ?>\n\t            &lt;?php if ( $video->post_mime_type == 'video\/webm' &amp;&amp; ! $video_webm ): $video_webm = true; ?>\n\t                &lt;source src=\"&lt;?php echo esc_url( $video->guid ); ?>\"\n\t                        type='video\/webm; codecs=\"vp8, vorbis\"'>\n\t            &lt;?php\n\t            $video_sources_shown++;\n\t            endif; ?>\n\t            &lt;?php if ( $video->post_mime_type == 'video\/ogg' &amp;&amp; ! $video_ogg ): $video_ogg = true; ?>\n\t                &lt;source src=\"&lt;?php echo esc_url( $video->guid ); ?>\"\n\t                        type='video\/ogg; codecs=\"theora, vorbis\"'>\n\t                &lt;?php esc_html_e( 'Video is not supporting by your browser', 'xstore' ); ?>\n\t            &lt;?php\n\t            $video_sources_shown++;\n\t            endif; ?>\n\t        &lt;?php endforeach; ?>\n\t    &lt;\/video>\n\t    &lt;?php return ob_get_clean() . str_replace('class=\"', 'class=\"hidden ', $image); ?> \n\t&lt;?php endif;\n\n\treturn $image; \n}, 10, 3);\n\nadd_filter('etheme_product_grid_list_product_element_image_wrapper_class', function($class, $product) {\n\tglobal $show_featured_as_video_data;\n\tif ( !is_array($show_featured_as_video_data) )\n\t\t$show_featured_as_video_data = array();\n\n\t$product_id = $product->get_id();\n\n\tif ( empty($show_featured_as_video_data) || !array_key_exists($product_id, $show_featured_as_video_data)) return $class;\n\n\tif ( isset($show_featured_as_video_data&#91;$product_id]&#91;'video_attachments']) &amp;&amp; count( $show_featured_as_video_data&#91;$product_id]&#91;'video_attachments'] ) > 0 ) {\n\t\t$class .= ' product-video-as-image';\n\t}\n\n\treturn $class;\n}, 10, 2);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Adding the code from this article to the child-theme\/functions.php file will display the videos uploaded in the product settings as the featured image on the Products Archive (shop, categories) pages.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"doc_category":[42],"doc_tag":[],"class_list":["post-2524","docs","type-docs","status-publish","hentry","doc_category-additional-customisation"],"aioseo_notices":[],"year_month":"2026-04","word_count":934,"total_views":"1010","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"author_nicename":"docs","author_url":"https:\/\/www.8theme.com\/documentation\/author\/docs\/"},"doc_category_info":[{"term_name":"Additional Customization","term_url":"https:\/\/www.8theme.com\/documentation\/xstore\/additional-customisation\/"}],"doc_tag_info":[],"author_list":[{"ID":"1","user_login":"docs","display_name":"docs","id":"1"}],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/docs\/2524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/comments?post=2524"}],"version-history":[{"count":6,"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/docs\/2524\/revisions"}],"predecessor-version":[{"id":2531,"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/docs\/2524\/revisions\/2531"}],"wp:attachment":[{"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/media?parent=2524"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=2524"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.8theme.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=2524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}