WPGraphQl Yoast SEO Plugin - Modified to produce schema that isn't broken for Gatsby-Source-WordPress
I have forked this version for one specific need.
If you're wanting to use Gatsby to generate your site, the Schema produced needs to have full URLs - but the Gatsby-source-wordpress plugin strips out the scheme and hostname from any URLs if they match the GraphQL endpoint - which is the case in any URLs produced for the Schema. In many cases, probably almost all cases, this behaviour is desirable and convenient. However, there's no scope for leaving specific elements alone - it's a blanket search and replace performed by a regex in the gatsby-source-wordpress code. This fork intercepts the data before it leaves WordPress and changes it to something that won't be recognised by that search and replace. Leaving everything else working as it should.
How To Set It Up
This gets a bit specific because it means you must have your WordPress administration screens on a different subdomain to your website generated by Gatsby. At the moment I have hardcoded that in this fork to be 'wpadmin.yoursite.com'. This is how I have mine setup, so I've run with that. In other words, Gatsby will replace any 'https://wpadmin.yoursite.com' prefixes with a simple '/' - not what we want in Schema.
This modification therefore turns all occurrences of wpadmin in the WPGraphQL output into simply www. This is because my Gatsby produced site lives on www.yoursite.com and my WordPress backend lives on wpadmin.yoursite.com. Hope that makes sense! If anyone actually uses this and wants it configurable then drop me a line and I'll see what I can do.
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
- Products (WooCommerce)
- 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
- Clone or download the zip of this repository into your WordPress plugin directory & activate the WP GraphQL Yoast SEO plugin
- Install & activate WPGraphQL
Composer
composer require snibbo71/wp-graphql-yoast-seo
Find this useful?
Canonicals
Please note canonicals will not be returned if you have the discourage search engines option turned on in your WordPress settings.
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 with Gatsby
Checkout the companion Gatsby plugin to add in Metadata and JSON LD schema with ease.
Usage
To query for the Yoast Data simply add the seo object to your query:
Post Type Data
query GetPages {
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
}
cornerstone
schema {
pageType
articleType
raw
}
readingTime
fullHead
}
author {
node {
seo {
metaDesc
metaRobotsNofollow
metaRobotsNoindex
title
social {
youTube
wikipedia
twitter
soundCloud
pinterest
mySpace
linkedIn
instagram
facebook
}
}
}
}
}
}
}
}
Post Taxonomy Data
query GetCategories {
categories(first: 10) {
edges {
node {
id
seo {
fullHead
canonical
title
metaDesc
focuskw
metaRobotsNoindex
metaRobotsNofollow
opengraphAuthor
opengraphDescription
opengraphTitle
opengraphDescription
opengraphImage {
altText
sourceUrl
srcSet
}
twitterTitle
twitterDescription
twitterImage {
altText
sourceUrl
srcSet
}
breadcrumbs {
url
text
}
}
name
}
}
}
}
User Data
query GetUsers {
users {
nodes {
seo {
metaDesc
metaRobotsNofollow
metaRobotsNoindex
title
fullHead
social {
youTube
wikipedia
twitter
soundCloud
pinterest
mySpace
linkedIn
instagram
facebook
}
}
}
}
}
Edge and Page Info Data
query GetPostsWithIsPrimary {
posts {
pageInfo {
startCursor
seo {
schema {
raw
}
}
}
nodes {
title
slug
categories {
edges {
isPrimary
node {
name
count
}
}
}
}
}
}
Yoast Config Data
query GetSeoConfig {
seo {
webmaster {
googleVerify
yandexVerify
msVerify
baiduVerify
}
schema {
siteName
wordpressSiteName
siteUrl
inLanguage
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
}
}
contentTypes {
post {
title
schemaType
metaRobotsNoindex
metaDesc
schema {
raw
}
archive {
fullHead
archiveLink
breadcrumbTitle
hasArchive
metaDesc
metaRobotsNoindex
title
}
}
page {
metaDesc
metaRobotsNoindex
schemaType
title
schema {
raw
}
}
}
redirects {
origin
target
format
type
}
}
}
Support
Please Note: Yoast and WPGraphQL and their logos are copyright to their respective owners.