2 min read
·
0 views

Making SEO better for blog posts with Structured Data

Search engines like Google use structured data to understand the contents of our page better. is a format that most use to describe the data.

Structured Data

Below is an example of a piece of structured data.


_10
{
_10
"@context": "https://json-ld.org/contexts/person.jsonld",
_10
"@id": "http://dbpedia.org/resource/John_Lennon",
_10
"name": "John Lennon",
_10
"born": "1940-10-09",
_10
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
_10
}

Source:

Adding Structured Data in Next.js

  1. Create the following component StructuredData.jsx. Here we use the built-in component from next/head to append elements to the head of the page.
StructuredData.jsx

_10
import Head from "next/head";
_10
_10
export const StructuredData = ({ data }) => {
_10
return (
_10
<Head>
_10
<script type="application/ld+json">{JSON.stringify(data)}</script>
_10
</Head>
_10
);
_10
};

  1. Use the StructuredData component in your respective component containing the UI for your post.
BlogPost.jsx

_23
export const BlogPost = ({ post }) => {
_23
const structuredData = {
_23
"@context": "https://schema.org",
_23
"@type": "Article",
_23
headline: post.title,
_23
description: post.description,
_23
author: [
_23
{
_23
"@type": "Person",
_23
name: post.author,
_23
},
_23
],
_23
image: post.imageUrl,
_23
datePublished: post.publishedAt,
_23
};
_23
};
_23
_23
return (
_23
<>
_23
<Structured data={structuredData} />
_23
{/* ... the rest of your blog post */}
_23
</>
_23
);

Validate Structured Data

Before deploying the changes to production, we can inspect the HTML elements on a browser to see if the changes are reflected in the <head> section of the page.

Upon successful deployment, we can use the to validate.