Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set meta tag dynamically in nextjs

how to use NextHead in next js and set open graph tag. I am passing props from the detail page but It is not appearing in the source.

<NextHead>
    <title>{title}</title>
    <meta property="og:type" content="website"/>
    <meta name="description" content={description}/>
    <meta property="og:title" content={title}/>
    <meta name="description" content={description}/>
    <meta name="keywords" content={keyword}/>
    <meta property="og:url" content={url}/>
    <meta property="og:description" content={description}/>
    <meta property="og:image" content={image}/>
</NextHead>
like image 401
vishal nakum Avatar asked Apr 24 '19 05:04

vishal nakum


People also ask

How can I add meta tags in Nextjs?

js. In the case of React, we need to install a package called react-helmet to add title and meta tags for each router component. Also, for adding routes or multiple pages in a react app, we need a package called react-router-dom.

Is next JS good for SEO?

This means that each page exists before being rendered by the browser client-side. In other terms, any web crawler can index them all effortlessly and treat them differently based on their content. So, Next. js is inherently an excellent tool to achieve great SEO performance.


1 Answers

You can see from the example here, next/head is imported and will add specific meta tag to the specific page.

import Head from 'next/head'

function IndexPage() {
  return (
    <div>
      <Head>
        <title>My page title</title>
        <meta name="viewport" content="initial-scale=1.0, width=device-width" />
      </Head>
      <p>Hello world!</p>
    </div>
  )
}

export default IndexPage

If this is not working, please provide the error message from your dev console. There should be some error that cause this approach not working.

like image 86
Darryl RN Avatar answered Oct 12 '22 02:10

Darryl RN