As you all know, we can choose custom image (social sharing image) only for collections (there’s an option to choose the image).
For product pages shopify takes the product image as social sharing image.
For all other pages shopify takes the picture from Online store preferences. This image is hardcoded in all pages (<meta property=“og:image” content=")
I want to apply custom images for a certain pages. So I need to find the way the replace the default og:image on certain pages to the one I need.
Yes, you can do so either by duplicating the template for each unique page and then edit it or by using an if condition to check for page handle (Liquid code) to add the appropriate image link.
not sure if this is still relevant as I can see that one of the answers have been marked as solved. However, I would like to let you know that we have just released an app SocialSeal.
This app enables you to set up personalized OG image templates for all your products and blog posts effortlessly. Easily adapt the font, font size, upload your logo, and choose custom colors that align with your brand’s identity and enhance your social media presence.
Does this solution provide a fallback when an image isn’t selected for a certain page? After the else statement, what will be pulled in from http:{{ page_image | image_url }} ?
Thanks @gregbanbury !
I just successfully implemented this using the code above. It’s been bothering me since I first signed up with Shopify that this isn’t a baked-in feature.
I created a metafield called ‘meta_image’ (“Add definition” in Settings > Custom data > Pages). Selected the metafield type ‘file’ from the ‘most used’ section. You will see image and video selected - I turned off video. Copy or make note of the ‘Namespace and key’ if you decide to call it something else as you need this exactly the same in the code that you put into your liquid file.
Then I went to ‘edit code’ in my theme and found the ‘social-meta.liquid’ file. Copied all that code into a blank word doc in case I blew things up. Then searched for the section that includes “page_image” and replaced it with Greg’s code above.
Finally, went to a page on my site and saw my new metafield and added an image. Then I went to Facebooks’s debugger page to check if the new image was showing. It took about 10 minutes before it scraped the new image.
Hope that helps. I’ve been searching for 2 years for a solution and am thrilled to have persevered and implemented one!