get media video youtube external_id in shopify to iframe
- User
get media video youtube external_id in shopify to iframe
- Assistant
To embed a YouTube video in Shopify using an
iframe, you can follow these steps:-
Get the external ID of the YouTube video:
- Go to the YouTube video page.
- Copy the characters after
v=in the video URL. For example, if the URL ishttps://www.youtube.com/watch?v=ABC123, the external ID isABC123.
-
Edit the Shopify theme to include the video in an
iframe:- From your Shopify admin, go to Online Store > Themes.
- Click on the Actions button and select Edit Code.
- Find the template file where you want to add the video. For example, if you want to add it to the product description, locate the
product-template.liquidfile. - Edit the template file and add the following code wherever you want the video to appear:
Replace<iframe width="560" height="315" src="https://www.youtube.com/embed/EXTERNAL_ID" frameborder="0" allowfullscreen></iframe>EXTERNAL_IDwith the YouTube video's external ID obtained earlier.
-
Save the changes and preview your store to see the embedded YouTube video.
-
- User
give me theme code in liquid
- Assistant
Sure! Here's an example of how you can add the YouTube video using an
iframein a Shopify theme template file:- Locate the theme template file where you want to add the video (e.g.,
product-template.liquid,page.liquid, etc.). - Edit the template file and add the following code wherever you want the video to appear:
{% assign youtubeVideoId = "EXTERNAL_ID" %} {% if youtubeVideoId != blank %} <div class="youtube-video"> <iframe width="560" height="315" src="https://www.youtube.com/embed/{{ youtubeVideoId }}" frameborder="0" allowfullscreen></iframe> </div> {% endif %}Replace
EXTERNAL_IDwith the actual external ID of your YouTube video.- Save the changes and preview your Shopify store to see the embedded YouTube video.
This code first checks if the
youtubeVideoIdvariable is not blank. If it has a value, it renders theiframewith the YouTube video using the providedEXTERNAL_ID. If theyoutubeVideoIdis blank, no video will be displayed. - Locate the theme template file where you want to add the video (e.g.,