Learn how to effectively use the SEO functions provided in seo.js to enhance your web pages for search engines.
This guide will walk you through the process of adding meta tags, structured data, and other SEO enhancements to your Next.js pages using generateMetaDataTags and getMetaData functions.
To set up SEO meta tags, you can utilize the generateMetaDataTags function from seo.js. Here's how you can integrate it into your pages:
1 import generateMetaDataTags from '@/lib/seo';2 3 const seoData = {4 title: 'Your Page Title',5 description: 'A brief description of your page',6 image: 'https://example.com/image.jpg',7 url: 'https://example.com/page',8 keywords: ['example', 'demo'],9 contentType: 'text/html',10 twitterHandle: '@example',11 siteName: 'Example Site',12 locale: 'en_US',13 canonicalUrl: 'https://example.com/page',14 alternateUrls: [{ lang: 'es', url: 'https://example.com/es/page' }]15 };16 17 <>{generateMetaDataTags(seoData)}</>getMetaData function. It allows you to set default values and override them as needed:1 import { getMetaData } from '@/lib/seo';2 3 const seoOptions = {4 title: 'Dynamic Page Title',5 description: 'Dynamic description based on content',6 keywords: ['dynamic', 'content'],7 openGraph: {8 title: 'Open Graph Title',9 description: 'Open Graph Description',10 url: 'https://example.com/dynamic-page'11 },12 canonicalUrlRelative: '/dynamic-page'13 };14 15 const metaData = getMetaData(seoOptions);16 // Use metaData in your component or pass to generateMetaDataTagsThe generateMetaDataTags function also includes a script for JSON-LD structured data, which you can customize according to your needs.