Next.js Discord

Discord Forum

Twitter Metadata

Unanswered
Bigeye tuna posted this in #help-forum
Open in Discord
Avatar
Bigeye tunaOP
why twitter metadata information not showing when i share url link to X (Twitter)? appear on other social media
Image

8 Replies

Avatar
Bigeye tunaOP
This is generateMetadata code

export async function generateMetadata({ params }) {
    const { slug } = params;

    const detailBerita = await fetchDetailBerita(slug);

    const optimizedImage = detailBerita.gambar.replace(
        /upload\//,
        'upload/w_1200,h_630,c_fill,q_75/'
    );

    return {
        title: detailBerita.judul,
        openGraph: {
            title: detailBerita.judul,
            description: htmlToText(detailBerita.isi, {
                wordwrap: 130,
                limits: { maxInputLength: 1000 },
            }),
            siteName: APP_CONFIG.NAME,
            publishedTime: new Date(detailBerita.created_at).toISOString(),
            modifiedTime: new Date(detailBerita.updated_at).toISOString(),
            images: [
                {
                    url: optimizedImage,
                    width: 1200,
                    height: 630,
                },
            ],
        },
        twitter: {
            card: 'summary_large_image',
            title: detailBerita.judul,
            description: htmlToText(detailBerita.isi, {
                wordwrap: 130,
                limits: { maxInputLength: 1000 },
            }),
            images: [
                {
                    url: optimizedImage,
                    alt: detailBerita.judul,
                },
            ],
        },
    };
}
Avatar
Are you using Vercel to publish it?
Usually it takes time for twitter cralwers to create a cache for the thumbnail preview
Avatar
Bigeye tunaOP
no, i use my own domain
so, nothing wrong with my metadata code?
Avatar
let me try
Avatar
at a glance, no. You can check if its working or not by checking locally on local build if the requried meta tags are there