I have developed a News Website using Next.js with Server Side Rendering. In my pages, I’m utilizing export const metadata = { title: "TEST" } to set the page title, but it doesn’t seem to have any effect. I have checked my implementation, and the metadata object appears to be correctly structured. However, the page title remains unchanged.
Repository : https://github.com/BlendEmini/NewsBlog-ssr
I would appreciate any insights or suggestions on why the metadata object is not affecting the page title as expected. If there’s a better approach or if I’m missing something crucial in the Next.js setup for server-side rendering, please guide me in the right direction. Thank you for your assistance!
I’ve tried several methods to set the page title in my Next.js News Website. Initially, I used the component, then attempted the older approach of defining metadata within the HTML, and finally, I adopted the recommended export const metadata method in each page file. Unfortunately, none of these methods have successfully changed the page title as expected. Despite meticulous checks, the title remains unaffected. I’m seeking guidance on potential issues or alternative approaches to ensure the correct display of page titles. Any assistance is appreciated.
2
Answers
You can install
next-seo
which is best for this type of website, where you can configure the seo settings for each and every web page.stackblitz
implementation reference
I see that you are using
pages
router instead ofapp
router. Hence, you can use<Head>
tag fromnext/head
.E.g.
For you reference: https://nextjs.org/docs/pages/api-reference/components/head