Prerequisites
- WordPress site with REST API enabled (default in WP 4.7+)
- Yoast SEO plugin installed and activated
- User account with
edit_postscapability - Application Password or Basic Auth credentials
Installation Methods
Choose one of the following installation methods. Both accomplish the same goal: exposing Yoast SEO fields via the REST API.Option A: MU-Plugin (Recommended)
Must-Use (MU) plugins are automatically activated and cannot be accidentally deactivated, making them ideal for critical functionality.Upload the plugin file
Upload
seo-machine-yoast-rest.php from the wordpress/ directory to:Create the
mu-plugins folder if it doesn’t exist in your wp-content directory.- Survives theme updates and changes
- Cannot be accidentally deactivated
- Clean separation from theme code
- Ideal for production environments
Option B: Functions.php Snippet
Add the code directly to your theme’sfunctions.php file or use a code snippets plugin.
Add to your site
Choose one method:Method 1: Child Theme (Recommended)Paste the code at the end of your child theme’s Method 2: Code Snippets PluginInstall a code snippets plugin like WPCode or Code Snippets:
functions.php:- Create a new snippet
- Paste the code
- Set to run everywhere
- Activate the snippet
- No new files to manage
- Works well with code snippet plugins
- Easy to modify for custom requirements
- Lost if theme is changed/updated (unless using child theme)
- Can be accidentally deactivated (if using snippets plugin)
Plugin Code
The MU-plugin registers custom REST API fields for Yoast SEO metadata:WordPress Configuration
Create Application Password
Navigate to user profile
In WordPress admin, go to Users → Profile (or Users → All Users and edit your user).
Generate application password
Scroll to the Application Passwords section at the bottom.
- Enter a name:
SEO Machine - Click Add New Application Password
- Copy the generated password immediately (it’s only shown once)
Configure SEO Machine
Add your WordPress credentials todata_sources/config/.env:
The application password includes spaces - keep them in the configuration.
API Usage
Once configured, SEO Machine can publish posts with Yoast SEO metadata using the WordPress REST API.Example: Create Post with SEO Metadata
Example: Update Existing Post
Using the Publish Command
SEO Machine provides a built-in command for publishing:- Converts Markdown to WordPress blocks
- Uploads images to WordPress media library
- Sets Yoast SEO metadata (focus keyphrase, SEO title, meta description)
- Creates the post as a draft for review
- Returns the post URL and edit link
Metadata Mapping
SEO Machine maps its internal metadata to Yoast SEO fields:| SEO Machine Field | Yoast SEO Field | WordPress Meta Key |
|---|---|---|
| Focus Keyphrase | Focus Keyphrase | _yoast_wpseo_focuskw |
| SEO Title | SEO Title | _yoast_wpseo_title |
| Meta Description | Meta Description | _yoast_wpseo_metadesc |
Security
The integration includes multiple security measures:Authentication
Authentication
- Requires valid WordPress credentials (application password or basic auth)
- All requests must include authentication headers
- Failed authentication returns 401 Unauthorized
Authorization
Authorization
Input Sanitization
Input Sanitization
- All inputs sanitized with
sanitize_text_field() - HTML tags stripped from metadata fields
- XSS protection built-in
Yoast Detection
Yoast Detection
- Plugin only registers fields if Yoast SEO is active
- Gracefully degrades if Yoast is deactivated
- No errors if Yoast is not installed
Troubleshooting
Authentication failed
Authentication failed
Problem: 401 Unauthorized errorSolutions:
- Verify application password is correct (including spaces)
- Ensure username is correct
- Check if Application Passwords feature is enabled (Settings → Permalinks, must not be “Plain”)
- Try regenerating the application password
Yoast fields not appearing
Yoast fields not appearing
Problem:
yoast_seo field not available in API responseSolutions:- Verify Yoast SEO plugin is installed and activated
- Check that MU-plugin or functions.php code is active
- Confirm user has
edit_postscapability - Test API endpoint:
GET /wp-json/wp/v2/posts/123
Permission denied errors
Permission denied errors
Problem: 403 Forbidden when updating postsSolutions:
- Verify user has
edit_postcapability for the specific post - Check user role (Editor or Administrator required)
- Ensure user owns the post or has sufficient privileges
REST API not working
REST API not working
Problem: Cannot connect to REST APISolutions:
- Verify permalinks are NOT set to “Plain” (Settings → Permalinks)
- Check
.htaccessfile for REST API rewrites - Disable security plugins temporarily to test
- Confirm site URL is correct (https vs http)
Advanced Configuration
Custom Post Types
To support custom post types, modify the plugin to register fields for additional post types:Additional Yoast Fields
Extend the integration to include more Yoast SEO fields:Webhook Notifications
Trigger webhooks when posts are published via SEO Machine:Next Steps
Analytics Setup
Configure GA4, Search Console, and DataForSEO to track performance
Publishing Workflow
Learn the complete content creation and publishing workflow