0

i want add genre meta in my project but when I use other in metas for creat this my export html I get bellow tag

meta name="genre" content="Commodity prices"/>

but its wrong I wand get this tag

<meta name="genre" itemprop="genre" content="Commodity prices">

my code:

other: {
      genre: 'Commodity prices',
    },

I think in this version we can't add itemprop in metas

1 Answer 1

0

The other object within the Next.js export const metadata object doesn't currently support adding itemprop attributes to meta tags. However, there are a couple of alternative approaches to achieve the desired <meta name="genre" itemprop="genre" content="Commodity prices"> tag

Using head within getStaticProps or getServerSideProps

// Inside your page component

export async function getStaticProps() {
  // Fetch or generate data here
  const genre = 'Commodity prices';

  return {
    props: { genre },
  };
}

// Or, for server-side rendering

export async function getServerSideProps() {
  // Fetch or generate data here
  const genre = 'Commodity prices';

  return {
    props: { genre },
  };
}

function MyPage({ genre }) {
  return (
    <div>
      <head>
        <meta name="genre" itemprop="genre" content={genre} />
        {/* Other meta tags */}
      </head>
      {/* Your page content */}
    </div>
  );
}

Customizing Meta Tags with a Component

function MyMeta({ genre }) {
  return (
    <head>
      <meta name="genre" itemprop="genre" content={genre} />
    </head>
  );
}

Use the MyMeta component within your page component

function MyPage({ genre }) {
  return (
    <div>
      <MyMeta genre={genre} />
      {/* Your page content */}
    </div>
  );
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.