Git Product home page Git Product logo

plugin-seo's Introduction

Payload SEO Plugin

NPM

A plugin for Payload CMS to auto-generate SEO meta data based on the content of your documents.

Core features:

  • Adds a meta field to every SEO-enabled collection or global. It:
    • includes title, description, and image subfields
    • auto-generates meta data from your document's content
    • displays hints and indicators to help content editors
    • renders a snippet of what a search engine might display
    • soon will support variable injection

Installation

  yarn add @payloadcms/plugin-seo
  # OR
  npm i @payloadcms/plugin-seo

Basic Usage

In the plugins array of your Payload config, call the plugin with options:

import { buildConfig } from 'payload/config';
import seo from '@payloadcms/plugin-seo';

const config = buildConfig({
  collections: [
    {
      slug: 'pages',
      fields: []
    },
    {
      slug: 'media',
      upload: {
        staticDir: // path to your static directory,
      },
      fields: []
    }
  ],
  globals: [
    {
      slug: 'homePage',
      fields: []
    }
  ],
  plugins: [
    seo({
      collections: [
        'pages',
      ],
      globals: [
        'homePage',
      ],
      uploadsCollection: 'media',
      generateTitle: ({ doc }) => `Website.com — ${doc.title.value}`,
      generateDescription: ({ doc }) => doc.excerpt
    })
  ]
});

export default config;

Options

  • collections

    An array of collections slugs to enable SEO. Enabled collections receive a meta field which is an object of title, description, and image subfields.

  • globals

    An array of global slugs to enable SEO. Enabled globals receive a meta field which is an object of title, description, and image subfields.

  • uploadsCollection

    An upload-enabled collection slug, for the meta image to access.

  • tabbedUI

    Display SEO meta fields in a separate tab using Payload's tabs UI component (Default: false)

  • generateTitle

    A function that allows you to return any meta title, including from document's content.

    seo({
      ...
      generateTitle: ({ doc, locale }) => `Website.com — ${doc?.title?.value}`,
    })
  • generateDescription

    A function that allows you to return any meta description, including from document's content.

    seo({
      ...
      generateDescription: ({ doc, locale }) => doc?.excerpt?.value
    })
  • generateImage

    A function that allows you to return any meta image, including from document's content.

    seo({
     ...
     generateImage: ({ doc, locale }) => doc?.featuredImage?.value
    })
  • generateURL

    A function called by the search preview component to display the actual URL of your page.

    seo({
      ...
      generateURL: ({ doc, locale }) => `https://yoursite.com/${doc?.slug?.value}`
    })

    TypeScript

    All types can be directly imported:

    import {
      SEOConfig,
      GenerateTitle,
      GenerateDescription
      GenerateURL
     } from '@payloadcms/plugin-seo/dist/types';

    Screenshots

    image

plugin-seo's People

Contributors

alessiogr avatar jacobsfletch avatar jesschowdhury avatar jmikrut avatar kalon-robson avatar rsisson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.