如何在Next.js 13中使用静态元数据对象添加自定义元标签?

huangapple go评论69阅读模式
英文:

How can I add custom meta tags using static metadata objects in next.js 13

问题

export const metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};
export const metadata = {
  other: { pinterest: "nopin" },
};

EDIT (April 18th):
I'm not sure why it seemed to be working before, but adding the meta tag as suggested by Mathieu (and the documentation) doesn't seem to actually work.

英文:

So I know that to block Pinterest on my site I need to embed this in my site's header <meta name="pinterest" content="nopin" />, but I'm not sure how to do that in Next 13 using the new exported metadata object format? Looked at the documentation for that object but couldn't figure it out.

export const metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

EDIT (April 18th):
I'm not sure why it seemed to be working before, but adding the meta tag as suggested by Mathieu (and the documentation) doesn't seem to actually work.

I have this in my root layout file and pinterest pinning option still appears on my site

export const metadata = {
  other: { pinterest: "nopin" },
};

答案1

得分: 2

添加自定义元数据,您可以使用其他类别:

export const metadata = {
  other: { pinterest: "nopin" },
};

下一个构建将生成以下元数据:

<meta name="pinterest" content="nopin"/>

更多信息请参阅:https://beta.nextjs.org/docs/api-reference/metadata#other

英文:

to add custom metadata, you can use other category:

export const metadata = {
  other: { pinterest: &quot;nopin&quot; },
};

next build will generate this metadata:

&lt;meta name=&quot;pinterest&quot; content=&quot;nopin&quot;/&gt;

More information here: https://beta.nextjs.org/docs/api-reference/metadata#other

答案2

得分: -3

将您的代码片段放入您的layout.js或page.js文件中,如下所示:

export const metadata = {
  ...[您之前的元数据如标题描述等]
  pinterest: "nopin"
};
英文:

it seems you just have to put your piece of code in your layout.js or page.js, like this :

export const metadata = {
  ...[Your previous meta data, like title, description,...]
  pinterest: &quot;nopin&quot;
};

huangapple
  • 本文由 发表于 2023年4月4日 16:05:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926931.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定