Repository navigation
Shopify custom image outputs a broken tag when no image is selected? Guard the empty value #51
vistabylara-dev
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
إذا لم تُحدَّد صورة، تجنّب تمرير قيمة فارغة إلى فلاتر الصور.
Free Shopify code series · 48/50 · Reviewed 24 October 2026
The problem
A custom image component may assume a chosen image always exists. Guard the value before requesting an image URL and provide an intentional text fallback.
Placement and precautions
Duplicate the theme and work in its unpublished preview. Save the original files and change one component at a time.
Use inside a product context for a simple image component. Merge the fallback translation. Preserve the responsive sizing and loading priority from your existing image component when integrating this guard.
Bounded Liquid example — not a replacement for an entire theme file:
{% if product.featured_image != blank %} {{ product.featured_image | image_url: width: 600 | image_tag }} {% else %} <p>{{ 'vbl_48.fallback' | t }}</p> {% endif %}Translation keys: Merge this object into the root of the existing locales/en.default.json, keeping all other keys and valid commas. Add corresponding translations to every active language file. Replace generic example wording with accurate store content. Do not replace the entire locale file.
{ "vbl_48": { "fallback": "Image not available" } }Check in preview
Preview a product with an image and one without. Check there is no empty src request or misleading stock photograph. Test translated fallback text and layout dimensions.
Limits to understand
This does not fix a network failure for an existing image or implement a media gallery. Loading priority must match placement; the main above-fold image must not become lazy-loaded.
Validation: This code and locale JSON passed Shopify's validation tool. This is static validation, not proof of rendering, accessibility, theme compatibility, indexing or improved sales. No live merchant store was changed or purchase performed.
Rollback
Restore the saved markup and styles if anything regresses. Remove any new calls before deleting their referenced files. Remove only unused locale keys introduced for this example. Keep the previous working theme available until the full affected journey has been checked.
Need this fixed in your store?
Send Dr Lara your store URL, theme name, affected page and what changed before the issue started. Start with free guidance and a free initial consultation. If you want implementation, we agree the scope and fee separately before work starts.
Explore Shopify repairs and development with Vista by Lara
WhatsApp Dr Lara about guide 48 or call +971 50 799 4292.
Free guidance. No commitment. Practical implementation is separately scoped.
Join the discussion
What result do you see, and what should happen instead? Share a short sanitized example. Remove passwords, tokens, customer details and private admin URLs.
Official references
Dr Lara · Vista by Lara · Dubai, UAE
All reactions