I've built a NEXT JS site and i'm trying to insert metatags that will make my posts on e.g. LinkedIn & FB look nice & customized. Here's the code I've used and inserted into my index.js site:
export default function Home() {
return (
<>
<Layout>
<Head>
<meta property="og:type" content="website" />
<meta property="og:title" content="Business- und Karrierecoaching" />
<meta
property="og:description"
content="Beratung und Begleitung in jeder Phase Ihres Berufslebens!"
/>
<meta
property="og:image"
content="https://anjavojta.com/wp-content/uploads/2023/10/title_photo_blue.png"
/>
<meta property="og:url" content="https://marliestheresbrunner.at" />
</Head>
<Hero />
</Layout>
</>
);
}
Here is my folder structure:
Still, the tags are not being scraped and if I use https://www.linkedin.com/post-inspector/ it's even telling me that "no og:image is found".
The output being shown (for instance on a LinkedIn post) is always code from my Hero component which is weird. I don't have any metatags inserted in my Hero component. Here is the code to my Hero component (which is inside the folder "components" - see folder structure in the image above):
export default function Hero() {
return (
<>
<Head>
<title>Business- und Karrierecoaching</title>
</Head>
<div css={pageContainer}>
<div css={heroContainer}>
<div css={heroHeadingContainer}>
Business- <br />
und Karrierecoaching
</div>
<div css={heroSubheadingContainerItalic}>
<i>Einstieg – Aufstieg – Orientierung – Veränderung – Neustart</i>
</div>
<div css={heroSubheadingContainer}>
Beratung und Begleitung in jeder Phase <br />
Ihres Berufslebens!
</div>
<Link href="/offer/" css={buttonStylesBlue}>
Mein Angebot
</Link>
<Link href="/contact" css={buttonStylesLight}>
Infogespräch
</Link>
<div css={signatureStyles}>
<Image
src={'/images/signature.png'}
alt="Unterschrift von Marlies Theres Brunner"
width={397}
height={120}
/>
</div>
</div>
</div>
</>
);
}
Thank you so much for the help!
Anja
Here's what I've tried so far (and didn't work either):
- put the metatags into my _app.js & Hero component Head instead
- changed the image url
Problem :
Possible Cause :
Solution :
Here's a small example code I made : (copy-paste & run in it)
Outcome : (i made a build & tested for presence of metadata, they were present)
Explanation :
Hero component
withHead
tag.nomd
which has noHead
tag (or metadata of any kind, just content)md
which has its ownHead
tagHero component
, it gets metadata from componentNextJS Version :
14.0.1
Folder Structure :
_document.js :
projectName\pages\_document.js
_app.js
projectName\pages\_app.js
:index.js
projectName\pages\index.js
(i have added links, to easily navigate between pages to see title & metadata change):index.js (hero page)
projectName\pages\hero\index.js
:Hero Component
projectName\components\Hero.js
:md page
projectName\pages\md\index.js
:nomd page
projectName\pages\nomd\index.js
:Output :
Keep Dev Tool's
Elements Tab
open,On going to home page (
http://localhost:3000/), Title = Homepage (title from _app.js
) & metadata inHead
tag from _app.jsOn going to hero page (
http://localhost:3000/hero
), Title = Title by Hero Compononent & metadata inHead
tag from Hero CompononentOn going to md page (
http://localhost:3000/md
), Title = MD PAGE & metadata from its ownHead
tagOn going to nomd page (
http://localhost:3000/nomd
), Title = Homepage (title from _app.js) & metadata in
Head` tag from _app.js<meta name="keywords" content="MY, WEBSITE, KEYWORDS">
is present on all pages, which i placed in_document.js
Please Read :
<title>
should not be used in _document.js<Head>
https://nextjs.org/docs/messages/no-document-titleMetadata : https://nextjs.org/docs/pages/building-your-application/optimizing#metadata
Head: https://nextjs.org/docs/pages/api-reference/components/head