ashhitch/wp-graphql-yoast-seo

Query Yoast SEO data with wp-graphql

Installs: 2 357

Dependents: 0

Suggesters: 0

Security: 0

Stars: 79

Watchers: 5

Forks: 16

Open Issues: 3

Type:wordpress-plugin

v4.5.0 2020-07-13 18:20 UTC

README

Latest Stable Version Total Downloads Monthly Downloads

WPGraphQl Yoast SEO Plugin

Please note version 14 of the Yoast Plugin is a major update.

If you are stuck on version of Yoast before V14 then use v3 of this plugin.

This is an extension to the WPGraphQL plugin (https://github.com/wp-graphql/wp-graphql) that returns Yoast SEO data.

Using this plugin? I would love to see what you make with it. 😃 @ash_hitchcock

Currently returning SEO data for:

  • Pages
  • Posts
  • Custom post types
  • Categories
  • Custom taxonomies
  • WooCommerce Products
  • Yoast Configuration
    • Webmaster verification
    • Social profiles
    • Schemas
    • Breadcrumbs

If there is any Yoast data that is not currently returned, please raise an issue so we can add it to the roadmap.

Quick Install

  1. Install & activate WPGraphQL
  2. Clone or download the zip of this repository into your WordPress plugin directory & activate the WP GraphQL Yoast SEO plugin

Composer

composer require ashhitch/wp-graphql-yoast-seo

V4 breaking change

Plugin now requires at least Yoast 14.0.0

V3 breaking change

Image urls are now returned as mediaItem type.

This applies to twitterImage and opengraphImage

Usage

To query for the Yoast Data simply add the seo object to your query:

{
  pages(first: 10) {
    edges {
      node {
        id
        title
        seo {
          canonical
          title
          metaDesc
          focuskw
          metaRobotsNoindex
          metaRobotsNofollow
          opengraphAuthor
          opengraphDescription
          opengraphTitle
          opengraphDescription
          opengraphImage {
            altText
            sourceUrl
            srcSet
          }
          opengraphUrl
          opengraphSiteName
          opengraphPublishedTime
          opengraphModifiedTime
          twitterTitle
          twitterDescription
          twitterImage {
            altText
            sourceUrl
            srcSet
          }
          breadcrumbs {
            url
            text
          }
        }

        author {
          seo {
            metaDesc
            metaRobotsNofollow
            metaRobotsNoindex
            title
            social {
              youTube
              wikipedia
              twitter
              soundCloud
              pinterest
              mySpace
              linkedIn
              instagram
              facebook
            }
          }
        }
      }
    }
  }


  categories(first: 10) {
    edges {
      node {
        id
        seo {
          canonical
          title
          metaDesc
          focuskw
          metaRobotsNoindex
          metaRobotsNofollow
          opengraphAuthor
          opengraphDescription
          opengraphTitle
          opengraphDescription
          opengraphImage {
            altText
            sourceUrl
            srcSet
          }
          twitterTitle
          twitterDescription
          twitterImage {
            altText
            sourceUrl
            srcSet
          }
          breadcrumbs {
            url
            text
          }
        }
        name
      }
    }
  }


  users {
    nodes {
      seo {
        metaDesc
        metaRobotsNofollow
        metaRobotsNoindex
        title
        social {
          youTube
          wikipedia
          twitter
          soundCloud
          pinterest
          mySpace
          linkedIn
          instagram
          facebook
        }
      }
    }
  }
}


To query for the site configuration data you can query from the root.

{
  posts {

  }

  seo {
    webmaster {
      googleVerify
      yandexVerify
      msVerify
      baiduVerify
    }
    schema {
      siteName
      wordpressSiteName
      siteUrl
      companyName
      companyOrPerson
      companyLogo {
        mediaItemUrl
      }
      logo {
        mediaItemUrl
      }
      personLogo {
        mediaItemUrl
      }
    }
    breadcrumbs {
      showBlogPage
      separator
      searchPrefix
      prefix
      homeText
      enabled
      boldLast
      archivePrefix
      notFoundText
    }
    social {
      facebook {
        url
        defaultImage {
          mediaItemUrl
        }
      }
      instagram {
        url
      }
      linkedIn {
        url
      }
      mySpace {
        url
      }
      pinterest {
        url
        metaTag
      }
      twitter {
        cardType
        username
      }
      wikipedia {
        url
      }
      youTube {
        url
      }
    }
    openGraph {
      frontPage {
        title
        description
        image {
          altText
          sourceUrl
          mediaItemUrl
        }
      }
      defaultImage {
        altText
        sourceUrl
        mediaItemUrl
      }
    }
    # Redirects only work in the premium version of Yoast
    redirects {
      origin
      target
      format
      type
    }
  }
}

Notes

This can be used in production, however it is still under active development, breaking changes will only be introduced with major version releases.

Support

Open an issue

Twitter: @ash_hitchcock

Contributors (PRs and Issues)

contributors.svg