ashhitch / wp-graphql-yoast-seo
Query Yoast SEO data with wp-graphql
Fund package maintenance!
ashhitch
www.buymeacoffee.com/ashhitch
Installs: 141 525
Dependents: 0
Suggesters: 0
Security: 0
Stars: 227
Watchers: 8
Forks: 48
Open Issues: 22
Type:wordpress-plugin
Requires
Requires (Dev)
Suggests
- wp-graphql/wp-graphql: Required to return data via GraphQl
- yoast/wordpress-seo: Required to provide SEO data to this plugin
- dev-master
- v4.23.2
- v4.23.1
- v4.23.0
- v4.22.5
- v4.22.4
- v4.22.3
- v4.22.2
- v4.22.1
- v4.22.0
- v4.21.0
- v4.20.0
- v4.19.0
- v4.18.1
- V4.18.0
- v4.17.0
- v4.16.2
- v4.16.1
- v4.16.0
- v4.15.1
- v4.15.0
- v4.14.2
- v4.14.1
- v4.14.0
- v4.13.1
- v4.13.0
- v4.12.1
- v4.12.0
- v4.11.0
- v4.10.2
- v4.10.1
- v4.10.0
- v4.9.0
- v4.8.0
- v4.7.1
- v4.7.0
- v4.6.0
- v4.5.5
- v4.5.4
- v4.5.3
- v4.5.2
- v4.5.1
- v4.5.0
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.0
- v4.0.1
- v4.0.0Alpha
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.0
- v2.1.0
- dev-feature/split-code
- dev-feature/docker
- dev-feature/taxonomyArchives
- dev-hotfix/meta-error
- dev-feature/socialProfiles
- dev-feature/code-tidy
- dev-feature/bug-scrub-jan-22
- dev-ashhitch-patch-1
- dev-feature/author-archives
- dev-feature/more-author-data
- dev-hotfix/tax-canonical
- dev-feature/yoast-16.7
- dev-feature/entity_decode
- dev-hotfix/undefined-indexes
- dev-feature/archive-meta
- dev-feature/reading-time
- dev-feature/schemaInPostTypeSettings
- dev-feature/full-schema-v2
- dev-feature/schema-v3
- dev-hotfix/opengraph-image-urls
- dev-feature/full-schema
- dev-phpcs
- dev-feature/update-examples
- dev-feature/content-types
- dev-hotfix/categories
- dev-feature/primary-category
- dev-feature/schema-fields
- dev-feature/open-graph
- dev-hotfix/site-schema
This package is auto-updated.
Last update: 2025-04-26 21:43:56 UTC
README
Please note version 4 of the Yoast Plugin is a major update.
If you are stuck on version of Yoast before V4 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
- Install from the WordPress Plugin Directory
- 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 ashhitch/wp-graphql-yoast-seo
Contributor Setup
This plugin uses Docker for local development to ensure a consistent environment for all contributors.
Prerequisites
Before you begin, make sure you have installed:
- Docker
- Docker Compose (usually included with Docker Desktop)
- Git
Getting Started
-
Clone the repository:
git clone https://github.com/ashhitch/wp-graphql-yoast-seo.git cd wp-graphql-yoast-seo
-
Start the Docker environment:
docker-compose up -d
This will build and start the following containers:
- WordPress (accessible at http://localhost:8000)
- MySQL database
- phpMyAdmin (accessible at http://localhost:8080)
-
Access WordPress:
The setup script will automatically:
- Install WordPress
- Install and activate the WPGraphQL plugin
- Install and activate the Yoast SEO plugin
- Activate the wp-graphql-yoast-seo plugin
- Create some test content (posts and pages)
Default credentials:
- Admin Username:
admin
- Admin Password:
password
- Admin Email:
admin@example.com
Development Workflow
-
Make your code changes to the plugin files in your local repository.
-
Test your changes:
- Visit http://localhost:8000 to access the WordPress admin
- You can use tools like GraphiQL (included with WPGraphQL) to test your GraphQL queries
-
Restart containers if needed:
docker-compose restart
-
View logs:
docker-compose logs -f wordpress
-
Stop the environment when you're done:
docker-compose down
To completely remove volumes (database data) as well:
docker-compose down -v
Coding Standards
This plugin follows WordPress Coding Standards. Before submitting a pull request:
-
Install development dependencies:
composer install
-
Run code quality checks:
composer run phpcs
-
Fix coding standards automatically (when possible):
composer run phpcbf
GraphQL Testing
To test your GraphQL queries with the WPGraphQL Yoast SEO plugin:
- Access the GraphiQL interface at http://localhost:8000/wp-admin/admin.php?page=graphiql-ide
- Try some of the example queries from the Usage section below
Troubleshooting
If you encounter issues:
-
Check container status:
docker-compose ps
-
Rebuild containers:
docker-compose down docker-compose build --no-cache docker-compose up -d
-
Check WordPress logs:
docker-compose logs wordpress
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 { meta { author { description title } date { description title } config { separator } homepage { description title } notFound { breadcrumb title } } 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 } otherSocials } 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 } } }
contentNode and nodeByUri
contentNode(id: "1", idType: DATABASE_ID) { id contentTypeName seo { title metaDesc } } node(id: "cG9zdDox",) { ... on NodeWithTitle { seo { title metaDesc } } } nodeByUri(uri: "/") { ... on NodeWithTitle { seo { title metaDesc } } }
Support
Please Note: Yoast and WPGraphQL and their logos are copyright to their respective owners.