DEV Community

Cover image for SEO in NextJS (How to use <NextSeo> tags in Nextjs 13/14) (npm i next-seo)
Sufian mustafa
Sufian mustafa

Posted on • Edited on

SEO in NextJS (How to use <NextSeo> tags in Nextjs 13/14) (npm i next-seo)

Benefits of SEO in Next.js:

  1. Automatic Head Management: Next.js simplifies the process of managing the document head, which includes crucial SEO elements such as title tags, meta descriptions, and canonical URLs. This is achieved using the component and the component.

2. Clean and Semantic URLs:

Next.js follows a file-based routing system, resulting in clean and semantic URLs. Search engines appreciate URLs that reflect the content hierarchy, positively influencing SEO.

3. Server-Side Rendering (SSR):

Next.js supports Server-Side Rendering, ensuring that the HTML is generated on the server and delivered to the client. This improves the speed of page rendering and positively impacts SEO, as search engines favor fast-loading pages.

  1. SEO-Friendly Routing: The file-based routing system in Next.js contributes to SEO-friendly URLs. Each page is represented by a corresponding file, making it easy to understand and optimize for search engines.

<NextSeo>Component in Detail:

import { NextSeo } from "next-seo";
import Head from "next/head";
import React from "react";

const AboutMePage = () => {
  return (
    <>
      <Head>
        <NextSeo
          title="About Me - Sufian Mustafa"
          description="Learn more about Sufian Mustafa, a passionate web developer with expertise in creating stunning web applications and websites"
          author="Sufian Mustafa"
          canonical="https://sufianmustafa.com/about"
          openGraph={{
            title: "About Me - Sufian Mustafa",
            description:
              "Get to know Sufian Mustafa, a web developer known for creating user-friendly and visually appealing websites. Discover his skills, experience, and passion for web development.",
            type: "webpage",
            url: "https://sufianmustafa.com/about",
            images: [
              {
                url: "https://res.cloudinary.com/dtvtphhsc/image/upload/v1697724760/Screenshot_248_tpjuk3.png",
                width: 800,
                height: 800,
                alt: "About Me - Sufian Mustafa",
              },
            ],
          }}
        />
      </Head>
      {/* Your About Me page Code goes here */}
    </>
  );
};

export default AboutMePage;

Enter fullscreen mode Exit fullscreen mode

Code Explanation:

  • <NextSeo> Component:
  • The NextSeo component is imported from the next-seo package. It's used to define SEO metadata for the current page.

  • ## <Head> Component:
    The Head component from Next.js is used to manage the document head, where metadata like title and meta tags are specified.

  • SEO Metadata:
    Inside the NextSeo component, various metadata is set:
    title and description: Define the title and description of the page for both SEO and Open Graph.
    author: Specifies the author of the page.
    canonical: Defines the canonical URL, providing search engines with the preferred URL for the page.

  • Open Graph (OG) Tags:
    Open Graph tags are crucial for social media sharing. They define how the content appears when shared on platforms like Facebook.
    openGraph object: Includes properties like title, description, type, url, and an array of images with their URLs, dimensions, and alt text.

This implementation ensures that your About Me page is not only well-optimized for search engines but also presents a polished appearance when shared on social media platforms.

Feel free to use and customize this code for other pages on your site, updating the metadata accordingly.

<Nextseo>npm link: (https://www.npmjs.com/package/next-seo)

PLz Add your reaction๐Ÿ’–
if you find it helpful! Happy coding! ๐Ÿš€

My wesite link [https://sufianmustafa.com/]

Top comments (0)