Don't forget about Open Graph

Website development
Open Graph protocol is a web standard originally developed by Facebook that turns any webpage into a graph object with title, description, image and so on. Even though there is no direct correlation between OG meta tags and improved SEO rankings, it still drives more traffic to your webpage by making it more “attractive” in social networks (Facebook, Twitter, Linkedin, etc).

An example of a link shared in Twitter that has «og:image» and «og:title».


Adding OG (and not only) meta tags into your React app

Without further due let’s jump into newly created React app with create-react-app and OG meta tags to /public/index.html. It should look like something like this:

<!DOCTYPE html>
      <meta charSet="utf-8"/>
      <meta http-equiv="x-ua-compatible" content="ie=edge"/>
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
      <link rel="alternate" type="application/rss+xml" href="/rss.xml"/>
      <title>Awesome App</title>
      <meta property="og:title" content="Awesome app - the best app ever" />
      <meta property="og:type" content="website" />
      <meta property="og:image" content="" />
      <meta property="og:description" content="Describe stuff here." />
      <meta property="og:url" content="" />
      <noscript>This app works best with JavaScript enabled.</noscript>
      <div id="root"></div>

Dynamic tags

Now, what if I need to generate tags dynamically for every page? That’s easy!

We’ll use React Helmet. So let’s create a separate component for document head management, which will dynamically set title, description, image for the page.

import React from 'react';
import Helmet from 'react-helmet';

function SEO({ pageProps }) {
  return (
      <meta property="og:title" content={pageProps.title} />
      <meta property="og:image" content={pageProps.thumbnail} />
      <meta property="og:url" content={pageProps.url} />

export default SEO;

Wherever we want to set our meta tags, we’ll just mount SEO component to necessary arguments just like

<SEO pageProps={
  title: "Yet another page",
  url="" } />
Tags:open graphreact.js
Hubs: Website development
3.1k 2
Comments 3

Popular right now

Frontend Developer (React.js)
to 150,000 ₽TeachbaseМоскваRemote job
Frontend-разработчик React.js
from 40,000 to 80,000 ₽ПК «Энергосбережение»Remote job
Backend Development Engineer
from 200,000 ₽Pixel Networks LtdRemote job
Front-End разработчик (Vue.js/React.js)
from 40,000 to 60,000 ₽PENA AgencyRemote job
Разработчик Python/Django + React.js
from 130,000 to 170,000 ₽trunkdevRemote job

Top of the last 24 hours