DEV Community

Matsu
Matsu

Posted on • Updated on

Enhancing Link Previews: A Guide to Open Graph Meta Tags

Have you ever shared a link, only to find it lacking the eye-catching preview you were hoping for? I recently encountered this issue when sharing my portfolio website on messaging apps like WhatsApp. After a bit of exploration, I discovered the solution: Open Graph meta tags.

The Problem: Missing Previews
Upon deploying my portfolio website, I noticed a small hiccup—link previews weren't displaying as expected when shared on various platforms. This led me on a quest to enhance the link previews for a more appealing and informative presentation.

The Solution: Open Graph Meta Tags
After some research, I found that setting up Open Graph meta tags within the <head> section of the HTML document was the key to resolving the preview issue. Here's a snippet of what I added:

<meta property="og:title" content="Your Title Here">
<meta property="og:image" content="https://example.com/images/image.jpg">
<meta property="og:description" content="This is just an example page.">
<meta property="og:url" content="https://example.com/page.html">
<meta name="twitter:card" content="summary_large_image">

Enter fullscreen mode Exit fullscreen mode

Breaking Down Open Graph Tags
og:title: Sets the title of your content.
og:image: Specifies the image to display in the link preview.
og:description: Provides a brief description of the content.
og:url: Defines the canonical URL of your content.
twitter:card: Ensures compatibility with Twitter's card system, particularly useful for a large image summary.

One thing to note is that Open Graph meta tags may not support relative image paths. In my initial attempts, using a relative path for the image (/images/image.jpg) didn't work as expected. This limitation prompted me to host the image externally and use the absolute URL in the og:image tag.

Implementing Open Graph meta tags ensures that when you share a link, platforms recognize and display the desired title, image, and description, creating a more engaging and professional presentation.

Enhancing link previews with Open Graph meta tags is a simple yet powerful way to optimize the visibility of your content across various platforms. The next time you deploy a website or share a link, consider adding these meta tags to make your content stand out.

Console You Later!

Top comments (0)