Next.js Discord

Discord Forum

i want to setup an image for my default page of my app, how?

Answered
American Robin posted this in #help-forum
Open in Discord
American RobinOP
i wanted to setup an image for my default page of my app, but i dont know how. could anyone help me and tell me how i could set up an image for the default route? "/" ?

thanks for ur help!
Answered by American Robin
export const metadata = {
  openGraph: {
    title: "title",
    description: "description",
    images: [
      {
        url: "/public/opengraph-image.jpg",
        width: 1800,
        height: 1600,
        alt: "alt text",
      },
    ],
  },
};


is this wrong, maybe the url?
View full answer

56 Replies

American RobinOP
yes
American RobinOP
does this work
yes
American RobinOP
on the default "/"
route too
yes
add it in app/page.tsx
American RobinOP
i had the export const metadata on the layout.tsx
do i have to move it to the page.tsx?
@American Robin i had the export const metadata on the layout.tsx
metadata will set it globally and then you can override it on the per page basis
American RobinOP
oh i see
so in my case
since i dont have any routes
layout.tsx is fine ?
@American Robin layout.tsx is fine ?
well you need a route to make this work
American RobinOP
im only using "/"
@American Robin im only using "/"
yeah that is also a route
add it in page.tsx
American RobinOP
ah
oke i see
export const metadata = {
  openGraph: {
    title: 'Next.js',
    description: 'The React Framework for the Web',
    url: 'https://nextjs.org',
    siteName: 'Next.js',
    images: [
      {
        url: 'https://nextjs.org/og.png',
        width: 800,
        height: 600,
      },
      {
        url: 'https://nextjs.org/og-alt.png',
        width: 1800,
        height: 1600,
        alt: 'My custom alt',
      },
    ],
    locale: 'en_US',
    type: 'website',
  },
}
this one right?
American RobinOP
since my image would be in the public folder, i have to paste the url to it right
American RobinOP
how would it look, when i only use one image?
images: {
   ...
}


like this?
no array?
@American Robin tsx images: { ... } like this?
nope, just add one entry in the array
American RobinOP
do i have to only add the title, description and images? to the openGraph object
American RobinOP
so only the image would be enough?
@American Robin so only the image would be enough?
well if you just need image, then yes
if you want a proper embed like [This](https://nextjs.org) then you need to add them
American RobinOP
ah i see
oke ill try it
to see if it works i have to deploy it right
cant use it from localhost
or can i?
you can use ngrok
American RobinOP
ngrok?
American RobinOP
i tried it, but it didnt work
i mean the title and description are showing
but the image isnt
American RobinOP
export const metadata = {
  openGraph: {
    title: "title",
    description: "description",
    images: [
      {
        url: "/public/opengraph-image.jpg",
        width: 1800,
        height: 1600,
        alt: "alt text",
      },
    ],
  },
};


is this wrong, maybe the url?
Answer
American RobinOP
@@ts-ignore ah its in the prod, tried it, but its showing a localhost url, how would i change that?
like the full https:// url
@@ts-ignore like the full https:// url
American RobinOP
if its in the public folder, how would that be?
@American Robin if its in the public folder, how would that be?
https://<site url>/opengraph-image.jpg
American RobinOP
ooooh i see
my /public/.. was to much
American RobinOP
@@ts-ignore thanks it worked!