Been trying to create a Metafield to show YouTube videos link or embed, to only specific products. I’ve tried multiple types (single, multi line, rich) neither work when i link the metafield to a product.
i see most solved cases showing adding a code in Theme liquid.. I do not have a THEME.liquid in my code files.. Theme: Horizon. Please help..
Metafield name is custom.product_video
What type to have it , what code to input and where?
First, we need to create a metafield definition for your products.
Go to your Shopify Admin and navigate to Settings > Custom data.
Select Products, then click on Add definition.
For the “Name”, enter “Product Video”.
The “Namespace and key” should be custom.product_video.
For the “Select type”, choose Multi-line text.
Click Save.
Step 2: Add the Video Embed Code to a Product:
Now you can add a video to any product you want.
Go to Products in your Shopify admin and select the product you want to add the video to.
Scroll down to the Metafields section at the bottom of the page.
You will see the “Product Video” metafield you just created. Click inside the empty field.
Go to the YouTube video you want to use, click on Share, and then select Embed. Copy the entire HTML embed code.
Paste this embed code into the “Product Video” metafield on your product page in Shopify.
Click Save.
Step 3: Display the Video on Your Product Page:
Finally, let’s make the video appear on your live store.
From your Shopify admin, go to Online Store > Themes.
On your Horizon theme, click the Customize button.
Using the dropdown menu at the top of the page, navigate to Products > Default product.
On the left-hand sidebar, under the “Product information” section, click on Add block and choose Custom Liquid.
A new “Custom Liquid” block will be added to your product page template. In the code box for this block, paste the following line: {{ product.metafields.custom.product_video.value }}
You can now drag and drop the “Custom Liquid” block to position the video wherever you would like it to appear on the page (e.g., under the product description).
Click Save in the top right corner.
Now, the video will automatically appear on any product where you have added the embed code to the metafield.
Thank you again for this it worked great ! now I have 2 different questions if its possible to do.
1) Use an embed code for a video carousel app I have on my shopify
instead of a single YouTube single video - will something like this code below be possible?
2) If above is not possible, is there a way to add two YouTube videos, so 2 different metafields?
With 1 metafield (custom.product_video) + linking it to a product + adding this CSS Liquid on the Theme builder default product {{ product.metafields.custom.product_video.value }} works ok
I tried creating another metafield “custom.product_video_2” and adding another CSS liquid {{ product.metafields.custom.product_video.value_2}} but only the prev 1 appears.
You were very close to solving this. The issue was a small typo in the Liquid code you tried for the second video.
Here is the corrected approach:
Step 1: Create a Second Metafield
Go to Settings > Custom data > Products.
Click Add definition.
Name: Product Video 2
Namespace and key: custom.product_video_2 (This needs to be unique).
Type: Multi-line text.
Click Save.
Step 2: Add the Second Video’s Embed Code to Your Product
Go to the product page in your Shopify admin.
In the Metafields section, you will now see “Product Video” and “Product Video 2”.
Paste the YouTube embed code for your second video into the “Product Video 2” field.
Click Save.
Step 3: Add a Second “Custom Liquid” Block
Go to Online Store > Themes and click Customize on your Horizon theme.
Navigate to your default product page (Products > Default product).
In the left-hand sidebar, click Add block and choose Custom Liquid.
In the code box for this new block, paste the following code. Notice the key product_video_2 matches your second metafield.