How can I add a default og:image if the image is missing?

Member

by dudley , in category: SEO , 7 months ago

How can I add a default og:image if the image is missing?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by drew , 7 months ago

@dudley 

If you want to add a default og:image when the specified image is missing or cannot be loaded, you can do so by adding a fallback image in the og:image tag.


Here is an example of how to add a default og:image using HTML and the Open Graph protocol:

1
2
3
4
5
6
7
8
<meta property="og:image" content="https://example.com/image.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

<!-- fallback image in case the specified image is missing -->
<meta property="og:image" content="https://example.com/fallback-image.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />


In the example above, we have specified two og:image tags. The first one is the image that you want to use as the default image, and the second one is the fallback image that will be displayed if the first image is missing or cannot be loaded.


Make sure that the dimensions (width and height) of both images are the same to ensure that the image is displayed correctly on social media platforms.


By adding a fallback image, you ensure that your website always has an image to display when it is shared on social media, even if the specified image is not available.