Ever develÂoped a webÂsite? When’s the last time you looked at the metatags you’re using? If your answer is ​“who cares,” then what hapÂpens when you share a link to your webÂsite on Slack, LinkedIn, or any othÂer social media site? Does it look like this?
Scott’s right, that looks realÂly bad. You’ve seen links shared that look great before, how do we go from this terÂriÂble shared link, to someÂthing that looks great, like this?
The answer is metatags. In this post, I want to go over how you can make sure your conÂtent looks amazÂing when shared on othÂer websites.
ExamÂple #
Metatags are not speÂcifÂic to a frameÂwork, but are a uniÂverÂsal stanÂdard. This is how social media sites process what you want them to process. They also have the benÂeÂfit of helpÂing Google search engine crawlers corÂrectÂly idenÂtiÂfy your conÂtent. If your webÂsite doesn’t have any metatags, typÂiÂcalÂly a social media site will try to infer the inforÂmaÂtion they need, but they’re almost always wrong because it’s imposÂsiÂble to know the right details.
I’ll be showÂing how we can setÂup the right details in Nextjs
and React
, howÂevÂer, the raw html metatag strucÂture is the same for any web frameÂwork you’re using. Below is an examÂple of how I strucÂture my metatags for NexÂtjs v13 in the RootLayout
component.
This guarÂanÂtees that metatags are injectÂed into the headÂer, where they’re expectÂed to be, for any givÂen page. Their names are pretÂty self-explanaÂtoÂry, but some of the more imporÂtant ones are image, title, descripÂtion, and author. This is because these tags are the main pieces of inforÂmaÂtion shown in a social media card. Type is more useÂful for web crawlÂing, and can be ​“webÂsite” or ​“artiÂcle” as an example.
The reaÂson this examÂple is strucÂtured with props, instead of being hardÂcodÂed, is because we can pass the object below into the layÂout on any page. This makes it dynamÂic, and is espeÂcialÂly useÂful for [slug].tsx
pages (blogs or dynamÂiÂcalÂly genÂerÂatÂed content).
TrouÂbleshootÂing #
Once you’ve added metatags, how can you make sure it looks right? Some social media sites cache your webÂsite, so if you make changes they won’t be reflectÂed when you share a secÂond time to valÂiÂdate your metatags. We can solve this probÂlem by using some nice tools shared by the major social media sites:
- LinkedIn Post InspecÂtor — this is my favorite tool. This site does not cache data, so it’s always up-to-date with your site. It shows you issues, what tags it’s lookÂing for, and tips for improvÂing your tags.
- FaceÂbook SharÂing Debugger
- TwitÂter Card Validator
- Social Share PreÂview — This site is useÂful as a catch-all, howÂevÂer if your headÂer isn’t conÂfigÂured propÂerÂly, it might think everyÂthing is okay, but the actuÂal social media site may disagree
You can also pop open the inspect element
tool in your favorite browsÂer, and look at the header
tags manÂuÂalÂly to see if the metatags are showÂing up:
ConÂcluÂsion #
Metatags are pretÂty easy to impleÂment, and quick to valÂiÂdate if they’re workÂing. I highÂly recÂomÂmend setÂting up at least one staÂtÂic set of metatags, at a minÂiÂmum, so that if you share any page for your webÂsite, it will look realÂly nice. From there, you can add more and more dependÂing on how imporÂtant each page’s idenÂtiÂty is, and if you want difÂferÂent headÂer images or descripÂtions in the share link.
The real valÂue in adding metatags is how imporÂtant sweatÂing the details is to you. This is one highÂly pracÂtiÂcal and easy way to make your webÂsite shine in how shareÂable it is.
Looking for more like this?
Sign up for our monthly newsletter to receive helpful articles, case studies, and stories from our team.
Lessons Learned from our Associate Developer
September 13, 2023One of our Associate Software Developers, Rohit, reflects on his time at MichiganLabs working on a short-term project, what he learned about real-world development, and the software consultancy business model.
Read moreMaking your Android project modular with convention plugins
May 22, 2024Explore the journey of Gradle and build tools like it, particularly in the context of Android development. You'll learn the necessity of separating code into modules as projects grow and how Gradle convention plugins can streamline this process.
Read moreAutomatic artifact downloads inside PR comments
June 20, 2024Discover a method to streamline the process of accessing build artifacts from GitHub Actions by reducing the number of clicks needed to download them directly from a pull request (PR) comment.
Read more