A user needed help embedding YouTube videos from collection metafields on their Shopify store, with issues around video placement and sizing.
Initial Problem:
Video displayed but was left-aligned and too small
Needed centering and better visual design
Solutions Provided:
Used CSS flexbox (display: flex; justify-content: center;) to center the video
Increased video width to 80% with proper aspect ratio (16:9)
Added padding, box-shadow, and border-radius for improved aesthetics
Additional Requirements:
Hide section when no metafield exists (solved with {% if %} conditional logic)
Display second video side-by-side with first video when available
Ensure responsive design (side-by-side on desktop, stacked on mobile)
Final Implementation:
Used Liquid templating with conditional checks for both video1 and video2 metafields, CSS Grid for layout (display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr))), and responsive styling. The solution successfully displays one or two videos dynamically based on metafield availability.
Status: Resolved - user confirmed the final code works perfectly.
Summarized with AI on October 30.
AI used: claude-sonnet-4-5-20250929.
Hello,
we want to update our collection pages with metafield that show embedded youtube videos.
I have seen a great video and copied that code in a custom liquid section.
To improve the placement and design of the embedded YouTube video using metafields, follow these steps:
Fix Alignment (Center the Video)
Your issue is that the video is aligning to the left because it’s inside a div without centering styles. Modify your Liquid code like this:
{{ collection.metafields.custom.video1.value }}
Changes & Improvements
Centered the Video
. Used display: flex; justify-content: center; to align it in the middle.
Increased Video Size
. Set width: 80% (you can change this to 90% or max-width: 1000px depending on your preference).
Added Padding for Spacing
. Added padding: 20px 0; to give breathing room.
Added a Shadow Effect & Rounded Corners (Optional but improves aesthetics)
. box-shadow makes it stand out.
. border-radius: 10px; softens edges.
Alternative: Using a Video Section Instead of Custom Liquid
If you want to use a native Shopify “Video” section, it doesn’t support embedded videos directly via metafields, but you can use an iframe URL metafield and add it via the Shopify UI.
. Hiding the section if no metafield exists
. Displaying a second video next to the first (if available)
. Ensuring responsiveness (side-by-side on desktop, stacked on mobile)
Updated Code (Final Version) plz update the code with this new code
Use this in your Custom Liquid section on the collection page:
{% if collection.metafields.custom.video1.value or collection.metafields.custom.video2.value %}
{% if collection.metafields.custom.video1.value %}
<iframe src="{{ collection.metafields.custom.video1.value }}" allowfullscreen="">
</iframe>
{% endif %}
{% if collection.metafields.custom.video2.value %}
<iframe src="{{ collection.metafields.custom.video2.value }}" allowfullscreen="">
</iframe>
{% endif %}
{% endif %}
Key Fixes & Improvements
. Section is hidden if no metafield exists
. Second video appears next to the first if available
. Videos stay centered & responsive
. Better spacing and design
This will now only show the section when at least one video metafield is set, and if both are available, they will appear side-by-side on desktop and stacked on mobile.
Updated Code (Fix for Second Video Issue)
This version ensures: The section is hidden if neither video1 nor video2 exists.
If video1 exists, it displays.
If video2 exists, it appears next to video1 (on desktops) or below (on mobile).
Use this in your Custom Liquid section:
{% if collection.metafields.custom.video1.value or collection.metafields.custom.video2.value %}
{% if collection.metafields.custom.video1.value %}
{{ collection.metafields.custom.video1.value }}
{% endif %}
{% if collection.metafields.custom.video2.value %}
{{ collection.metafields.custom.video2.value }}
{% endif %}
{% endif %}
Fixes & Improvements:
. Fixed the second video issue – now both videos display properly side by side.
. Videos are centered.
. Section is hidden when no metafield exists.
. Now responsive – videos display side by side on large screens and stack on mobile.
. Padding & spacing improved – videos look better with gaps.
Try this updated code and let me know if both videos appear correctly now!