{"id":11402,"date":"2019-06-21T09:24:43","date_gmt":"2019-06-21T09:24:43","guid":{"rendered":"https:\/\/ampforwp.com\/tutorials\/?post_type=ht_kb&#038;p=11402"},"modified":"2020-05-07T12:09:50","modified_gmt":"2020-05-07T12:09:50","slug":"how-to-add-featured-video-in-place-of-featured-image","status":"publish","type":"ht_kb","link":"https:\/\/ampforwp.com\/tutorials\/article\/how-to-add-featured-video-in-place-of-featured-image\/","title":{"rendered":"How to add featured video in place of featured image"},"content":{"rendered":"\n<p>In AMP, if you want to display featured video instead of the featured image then follow the below steps.<\/p>\n\n\n\n<p>If you want featured video in Swift theme then follow this below steps but if you want feature video in Design 1, Design 2, and Design 3 then <a href=\"https:\/\/ampforwp.com\/tutorials\/article\/how-to-add-featured-video-in-place-of-featured-image\/#mce_31\">Click Here<\/a><\/p>\n\n\n\n<h4><mark style=\"background-color: yellow;\">\nFeatured video in Swift Theme<\/mark><\/h4>\n\n\n\n<p><strong>Step 1:<\/strong>  Create a folder with the name \u201c<strong>ampforwp<\/strong>\u201d in your theme which you are currently using.  <\/p>\n\n\n\n<p><strong>e.g: <\/strong>if you are using Twenty Seventeen theme then you have to create &#8220;<strong>ampforwp<\/strong>&#8221; folder in the twenty seventeen theme folder.<\/p>\n\n\n\n<p>The directory will look like<\/p>\n\n\n\n<p><strong>ex: wp-content\/themes\/twentyseventeen\/ampforwp<\/strong><\/p>\n\n\n\n<p><strong> Step 2:<\/strong>  Add the &#8220;<strong>single.php<\/strong>&#8221; file of the design which you are using in amp (Design1, Design 2, Design 3 and Swift theme)to override the featured image. <\/p>\n\n\n\n<p> The directory will look like <\/p>\n\n\n\n<p><strong>ex: wp-content\/plugins\/accelerated-mobile-pages\/templates\/design-manager\/swift\/single.php<\/strong><\/p>\n\n\n\n<p>In <strong>\u201csingle.php<\/strong>\u201d file you need to remove the below function name &#8211; amp_featured_image() and replace it with your custom function name like in below the screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"994\" height=\"349\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1.png\" alt=\"\" class=\"wp-image-11461\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1.png 994w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1-300x105.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1-768x270.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1-50x18.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1-60x21.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/remove-function-1-100x35.png 100w\" sizes=\"(max-width: 994px) 100vw, 994px\" \/><\/figure>\n\n\n\n<p>Below is the example code to fetch the featured video from meta filed you need to write this code in functions.php of your theme.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">function prefix_amp_featured_section(){\n\tglobal $post;\n\t\n\t$post_id = '';\t\n\t$post_id = $post-&gt;ID;\n\tif ( function_exists('ampforwp_get_the_ID')) {\n\t\t$post_id = ampforwp_get_the_ID();\n\t}\n\t\n\t$youtubelink = get_post_meta($post_id, 'Video', true);\n\t\n\tif (  $youtubelink ) {\n\t\t$str = explode(&quot;youtu.be\/&quot;, $youtubelink);\n\n\t\t\t$container_start = '\n \n\t\t\t\t\t\t\t\n \n\t\t\t\t\t\t\t\t\n';\n\t\t\t$container_end = '\n';\t\n\t\t\tif(!empty($str[1])){\n\t\t\t\techo $container_start. '' . $container_end;\n\t\t\t}\n\t} else {\n\t\treturn amp_featured_image();\n\t}\n\treturn;\n}<\/pre><\/div>\n\n\n\n<p>In the above code, we are calling &lt;amp-youtube&gt; tag and it&#8217;s mandatory to load Script for it.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">add_action( 'amp_post_template_head', 'prefix_amp_post_template_head', 100);\nfunction prefix_amp_post_template_head($amp_post_template){\n\t\/**\n\t * check if youtube video exists in the content\n\t *\/\n\tglobal $post;\n\t$post_id = '';\t\n\t$post_id = $post-&gt;ID;\n\tif ( function_exists('ampforwp_get_the_ID')) {\n\t\t$post_id = ampforwp_get_the_ID();\n\t}\n\t$youtubelink = get_post_meta($post_id, 'Video', true);\n\t$scripts = $amp_post_template-&gt;get( 'amp_component_scripts', array() );\n\t\n\t\/**\n\t * we don't need to add script if it already registered\n\t *\/ \n\tif (!empty($youtubelink) &amp;&amp; !isset($scripts['amp-youtube'])){\n\t\techo '';\n\t}\n\treturn;\n};<\/pre><\/div>\n\n\n\n<p>Replace the function name with your custom function name like in the below screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"986\" height=\"354\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1.png\" alt=\"\" class=\"wp-image-11474\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1.png 986w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1-300x108.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1-768x276.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1-50x18.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1-60x22.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/06\/c-f-1-1-100x36.png 100w\" sizes=\"(max-width: 986px) 100vw, 986px\" \/><\/figure>\n\n\n\n<h4 id=\"mce_31\"><mark style=\"background-color: yellow;\">\nFeatured video in Design 1, Design 2 and Design 3<\/mark><\/h4>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Create a folder with the name \u201c<strong>ampforwp<\/strong>\u201d in your theme which you are currently using.<\/p>\n\n\n\n<p><strong>e.g:&nbsp;<\/strong>if you are using Twenty Seventeen theme then you have to create \u201c<strong>ampforwp<\/strong>\u201d folder in the twenty seventeen theme folder.<\/p>\n\n\n\n<p>The directory will look like<\/p>\n\n\n\n<p><strong>ex: wp-content\/themes\/twentyseventeen\/ampforwp<\/strong><\/p>\n\n\n\n<p><strong>Step 2:<\/strong> Create a new folder with the name &#8220;<strong>elements<\/strong>&#8221; inside this folder add the \u201c<strong>featured-image.php<\/strong>\u201d file of the design which you are using in amp (Design1, Design 2, Design 3)to override the featured image.<\/p>\n\n\n\n<p>The directory will look like<\/p>\n\n\n\n<p><strong>ex: wp-content\/plugins\/accelerated-mobile-pages\/templates\/design-manager\/design1\/elements<\/strong>\/<strong>featured-image.php<\/strong> <\/p>\n\n\n\n<p>In&nbsp;<strong>\u201cfeatured-image.php<\/strong> \u201d file you need to remove the below variable name \u2013 $amp_html and replace it with your custom function name like in below the screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"368\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-1024x368.png\" alt=\"\" class=\"wp-image-12036\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-1024x368.png 1024w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-300x108.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-768x276.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-50x18.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-60x22.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1-100x36.png 100w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-1.png 1055w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Below is the example code to fetch the featured video from meta filed you need to write this code in functions.php of your theme.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">add_action('ampforwp_before_featured_image_hook', 'prefix_insert_featured_video');\nfunction prefix_insert_featured_video(){\n \n $youtubelink = prefix_get_video_id();\n\n if ($youtubelink) {\n echo '';\n }\n}\n\nadd_filter('has_post_thumbnail','prefix_disable_featured_image_on_video');\nfunction prefix_disable_featured_image_on_video($image){\n \n $youtubelink = prefix_get_video_id();\n\n if ($youtubelink ) {\n $image  = false;\n }\n\n return $image;\n}\nfunction prefix_get_video_id(){\n\n global $post;\n \n $post_id = ''; \n $post_id = $post-&gt;ID;\n if ( function_exists('ampforwp_get_the_ID')) {\n $post_id = ampforwp_get_the_ID();\n }\n \n $youtubelink = get_post_meta($post_id, 'Video', true);\n \n if ($youtubelink){\n $youtubelink = explode('?v=', $youtubelink);\n }\n\n if ( $youtubelink[1] == null ) {\n $is_small_url =  strpos($youtubelink[0], 'be\/');\n if ( $is_small_url) {\n $youtubelink = explode('be\/', $youtubelink[0]);\n }\n }\n\n if ( $youtubelink[1]) {\n return $youtubelink[1];\n }\n return false;\n}\n\ufeff<\/pre><\/div>\n\n\n\n<p>In the above code, we are calling &lt;amp-youtube&gt; tag and it\u2019s mandatory to load Script for it.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">add_filter( 'amp_post_template_data', 'prefix_add_youtube_video_script' );\nfunction prefix_add_youtube_video_script( $data ) {\n\t\n\t$video_id = &quot;&quot;;\n\t$video_id = prefix_get_video_id();\n\tif ($video_id ) {\n\t\tif ( empty( $data['amp_component_scripts']['amp-youtube'] ) ) {\n\t\t\t$data['amp_component_scripts']['amp-youtube'] = 'https:\/\/cdn.ampproject.org\/v0\/amp-youtube-0.1.js';\n\t\t}\t\n\t}\n\treturn $data;\n}\n<\/pre><\/div>\n\n\n\n<p>Replace variable name with your custom function name like in the below screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"264\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-1024x264.png\" alt=\"\" class=\"wp-image-12041\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-1024x264.png 1024w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-300x77.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-768x198.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-50x13.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-60x15.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2-100x26.png 100w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/r-2.png 1053w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption><br><\/figcaption><\/figure>\n\n\n\n<h4><mark style=\"background-color: yellow;\">\nHow to Add Featured Videos by using plugin<\/mark><\/h4>\n\n\n\n<p>If you are not a developer and you think this code might be difficult to add featured video in place of the featured image so we have a better solution for this by using &#8220;Featured Video Plus&#8221;  plugin you can easily place featured video for this you need to follow below steps:<\/p>\n\n\n\n<p><strong> Currently, we are fully compatible with Featured Video Plus plugin <\/strong><\/p>\n\n\n\n<p><strong>Step 1: <\/strong>First thing you need to do is install and activate the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/wordpress.org\/plugins\/featured-video-plus\/\" target=\"_blank\">Featured Video Plus <\/a>plugin. <\/p>\n\n\n\n<p><strong>Step 2:<\/strong>Now edit your posts and add video links to the Featured Video box on the right you can either include the URL for your featured video manually or click on the camera icon next to where it says Video URL<em>.&nbsp;<\/em> <br>Now pick a video from your media library and click on the Update button like below the screenshot. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"476\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-1024x476.png\" alt=\"\" class=\"wp-image-12636\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-1024x476.png 1024w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-300x139.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-768x357.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-50x23.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-60x28.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1-100x46.png 100w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-1.png 1343w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Step 3:<\/strong> Now you can check out your post from the front end and see how your featured video looks.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"501\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-1024x501.png\" alt=\"\" class=\"wp-image-12640\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-1024x501.png 1024w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-300x147.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-768x376.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-50x24.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-60x29.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2-100x49.png 100w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/07\/featured-video-2.png 1350w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>That\u2019s it for this tutorial!<\/strong><\/p>\n\n\n\n<p>We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.<\/p>\n<div id=\"div-1\" class=\"hkb-feedback\">\n\t\t\t<strong class=\"ht-mobile-exit__title\">Ask your Questions Directly!<\/strong><br>\n\t\t\t<div class=\"hkb_widget_exit__content\" style=\"font-size: 14px;\">If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!<\/div>\n\t\t\t<a href=\"https:\/\/ampforwp.com\/support\/#contact\" id=\"button\" target=\"_blank\" rel=\"noopener noreferrer\"><button>Yes, I have a Question<\/button><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In AMP, if you want to display featured video instead of the featured image then follow the below steps. If you want featured video in Swift theme then follow this below steps but if you want feature video in Design 1, Design 2, and Design 3 then Click Here Featured&#8230;<\/p>\n","protected":false},"author":18,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[34],"ht-kb-tag":[],"_links":{"self":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/11402"}],"collection":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/comments?post=11402"}],"version-history":[{"count":93,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/11402\/revisions"}],"predecessor-version":[{"id":17284,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/11402\/revisions\/17284"}],"wp:attachment":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/media?parent=11402"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-category?post=11402"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-tag?post=11402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}