Rank Math REST API Enabler
Installable WordPress plugin that writes a Must-Use (MU) plugin to register REST endpoints which read/write Rank Math meta fields. Provides a Settings page to control endpoints and inspect the MU plugin.
by Valandi Angelidis · github.com/valandiangelidis/rankmath-rest-api-enabler · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/valandiangelidis/rankmath-rest-api-enabler/archive/refs/heads/main.zipReadme
🧩 Rank Math REST API Enabler
Author: Valandi Angelidis
Email: info@valandiangelidis.com
GitHub: github.com/ValandiAngelidis
Version: 1.0.0
📖 Overview
Rank Math REST API Enabler is a professional WordPress plugin that automatically deploys a Must-Use (MU) plugin to expose Rank Math SEO meta fields via a secure REST API. It provides complete control over your Rank Math data through RESTful endpoints.
The plugin features a modern, professional admin interface (under Settings → Rank Math API) to manage the MU plugin, view API documentation, and access usage examples — all without touching code.
Perfect for:
- Developers building headless WordPress solutions
- Automation engineers using n8n, Make.com, or Zapier
- SEO agencies managing multiple sites
- Teams requiring programmatic access to Rank Math data
⚙️ Quick Installation
- Copy the
Rank Math REST API Enablerfolder into yourwp-content/plugins/directory. - Activate the plugin via Plugins → Installed Plugins.
- Automatic setup — on activation, the plugin will:
- Create the
wp-content/mu-plugins/directory if it doesn't exist - Generate the
rankmath-rest-api.phpMU plugin file automatically - Configure default settings for immediate use
- Create the
- Visit Settings → Rank Math API to view status and documentation.
Multisite Support: When network-activated, the MU plugin is automatically created for all sites in the network, including newly added sites.
✨ Key Features
-
🚀 Automatic Installation
MU plugin auto-generates on activation — no manual setup required -
🌐 Full Multisite Support
Network activation creates MU plugin for all sites; auto-installs on new sites -
🔄 Smart Version Management
Automatically updates MU plugin when plugin version changes -
💾 Safe Backups
Creates timestamped backups before overwriting existing files -
🧹 Clean Uninstall
Safely removes MU plugin and all settings on uninstallation -
🎨 Modern Admin Interface
Professional, card-based design with intuitive navigation -
📚 Built-in Documentation
Complete API reference, examples, and authentication guides -
🔒 Security-First Design
WordPress capability checks, nonce verification, and input sanitization
🔌 Available API Fields
The plugin exposes the following Rank Math meta fields:
| Field Name (API) | Meta Key | Description |
|---|---|---|
title |
rank_math_title |
SEO Title |
description |
rank_math_description |
SEO Meta Description |
focus |
rank_math_focus_keyword |
Focus Keyword(s) |
slug |
rank_math_permalink |
SEO Slug (Permalink) |
Note: Underscored fields (_rank_math_description, _rank_math_focus_keyword) are also synced for compatibility.
🧠 REST API Endpoints
GET Endpoint
Retrieve Rank Math meta fields for a post:
GET /wp-json/rankmath/v1/meta/{post_id}
Example Response:
{
"rank_math_title": "Best SEO Practices 2025",
"rank_math_description": "Complete guide to SEO optimization",
"rank_math_focus_keyword": "SEO practices",
"rank_math_permalink": "best-seo-practices-2025",
"_rank_math_description": "Complete guide to SEO optimization",
"_rank_math_focus_keyword": "SEO practices"
}
POST Endpoint
Update Rank Math meta fields:
POST /wp-json/rankmath/v1/meta/{post_id}
Content-Type: application/json
Example Request Body:
{
"title": "Updated SEO Title",
"description": "Updated meta description for better SEO",
"focus": "primary keyword, secondary keyword",
"slug": "updated-custom-slug"
}
Example Response:
{
"post_id": 123,
"updated": {
"rank_math_title": "Updated SEO Title",
"rank_math_description": "Updated meta description for better SEO",
"rank_math_focus_keyword": "primary keyword, secondary keyword",
"rank_math_permalink": "updated-custom-slug"
}
}
Permissions: Users must have edit_post capability for the specified post.
🔐 Authentication
Application Passwords (Recommended)
Create an Application Password under Users → Your Profile → Application Passwords.
cURL Example:
curl -u "username:application-password" \
"https://example.com/wp-json/rankmath/v1/meta/123"
PowerShell Example:
$cred = Get-Credential
Invoke-RestMethod -Uri 'https://example.com/wp-json/rankmath/v1/meta/123' `
-Method Get -Credential $cred
POST Request Example:
curl -u "username:application-password" \
-X POST \
-H "Content-Type: application/json" \
-d '{"title":"New Title","description":"New description"}' \
"https://example.com/wp-json/rankmath/v1/meta/123"
📋 Requirements
- WordPress 5.9 or higher
- PHP 7.4 or higher
- Rank Math SEO plugin (active)
- Write permissions to
wp-content/mu-plugins/directory
🧰 Admin Interface Features
The plugin provides a comprehensive settings page with:
-
MU Plugin Status Card
- Visual status indicators (✓/✗)
- File location and last modified time
- One-click reinstall button
-
API Documentation Card
- Complete field reference table
- REST endpoint URLs
- Available meta fields
-
Authentication Guide Card
- Ready-to-use cURL examples
- PowerShell examples
- Authentication best practices
-
Example Requests Card
- GET and POST examples
- Request/response samples
- JSON formatting
-
Support Information Card
- Author contact details
- Plugin version badge
- Helpful links
🧪 Testing
Verify Installation
- ✅ Activate plugin → check
/wp-content/mu-plugins/rankmath-rest-api.phpexists - ✅ Visit Settings → Rank Math API → verify green checkmarks
- ✅ Test GET endpoint with cURL or Postman
- ✅ Test POST endpoint with sample data
Multisite Testing
- ✅ Network activate on multisite
- ✅ Verify MU plugin created for all sites
- ✅ Add new site → verify auto-installation
- ✅ Test endpoints on different sites
🔒 Security Features
- ✅ WordPress capability checks (
edit_post) - ✅ Nonce verification on admin actions
- ✅ Input sanitization (
sanitize_title,wp_kses_post, etc.) - ✅ Path validation (ensures files written only to wp-content)
- ✅ Atomic file writes with temporary files
- ✅ Proper escaping of all output
🧑💻 Developer Notes
- The MU plugin is not removed on deactivation (by design) to prevent breaking active integrations
- MU plugin is fully removed on uninstallation for clean site cleanup
- Compatible with headless WordPress setups
- Works with WordPress REST API authentication plugins
- All strings are internationalization-ready (
.potfile included)
📜 License
Licensed under GNU General Public License v2.0+ (GPL-2.0+).
You are free to use, modify, and distribute this software under the same license.
🧑💻 Credits
Developed by Valandi Angelidis
Multidisciplinary creator & full-stack developer specializing in digital ecosystems, automation, and medical marketing technologies.
🌐 Website: valandiangelidis.com
💌 Email: info@valandiangelidis.com
💾 GitHub: github.com/ValandiAngelidis
🚀 Future Enhancements
- [ ] Inline API endpoint tester in admin UI
- [ ] Batch operations for multiple posts
- [ ] Webhook notifications on meta changes
- [ ] Enhanced logging and debugging tools
- [ ] REST schema documentation
- [ ] WP-CLI commands
⭐ Support & Contribute
Found this plugin helpful? Star the repository!
Want to contribute? Pull requests are welcome at:
👉 github.com/ValandiAngelidis/rankmath-rest-api-enabler
Made with ❤️ for the WordPress community
📖 Overview
Rank Math REST API Enabler is an installable WordPress plugin that automatically deploys a Must-Use (MU) plugin to expose Rank Math SEO meta fields (rank_math_title, rank_math_description, rank_math_focus_keyword, etc.) via a secure REST API.
It also provides a Settings page inside WordPress (under Settings → Rank Math API) to control endpoints, verify the MU plugin status, and reinstall or debug it — all without touching code.
Designed for developers, automation engineers, and SEO agencies who integrate Rank Math data with tools like n8n, Make.com, or Zapier.
⚙️ Quick Installation
- Copy the folder
rankmath-rest-api-enablerinto yourwp-content/plugins/directory. - Activate the plugin via Plugins → Installed Plugins.
- On activation, it will:
- Ensure the directory
wp-content/mu-plugins/exists (create it if not). - Write a file named
rankmath-rest-api.phpinside that directory.
- Ensure the directory
- Visit Settings → Rank Math API to:
- Enable/disable endpoints,
- View MU plugin status,
- Reinstall or inspect the MU plugin code.
If file creation fails, an admin notice will inform you.
✨ Key Features
- 🔧 Automatic MU plugin installation on activation
Creates/wp-content/mu-plugins/rankmath-rest-api.phpautomatically. - ♻️ Version-based overwrite
MU plugin is updated when the main plugin version changes. - 💾 Automatic backup
Existing MU plugin is renamed to*-bak-YYYYmmdd-HHMMSS.phpbefore overwrite. - 🧠 Admin UI controls
Enable/disable GET or POST endpoints, toggle meta synchronization, and manage admin notices. - 🧩 Live code viewer
Displays the current MU plugin code on the settings page for transparency/debugging. - 🧪 Syntax test utilities
Includes PowerShell and PHP CLI scripts for linting and syntax checking.
⚙️ Settings Structure
Plugin options are stored in the WordPress option key
rankmath_rest_api_enabler_settings
with the following structure:
[
'enable_get' => true,
'enable_post' => true,
'sync_fields' => true,
'show_notices' => true,
]
🔐 Authentication for API Testing
You can authenticate using WordPress Application Passwords (recommended).
Create one under Users → Profile → Application Passwords, then use it with your username.
Example — cURL:
bash
Copy code
curl -u "username:application-password" "https://example.com/wp-json/rankmath/v1/meta/123"
Example — PowerShell:
powershell
Copy code
$cred = Get-Credential
Invoke-RestMethod -Uri 'https://example.com/wp-json/rankmath/v1/meta/123' -Method Get -Credential $cred
🧠 Endpoints
Method Endpoint Description
GET /wp-json/rankmath/v1/meta/{post_id} Retrieve Rank Math meta fields for the post
POST /wp-json/rankmath/v1/meta/{post_id} Update Rank Math meta fields (title, description, focus)
Example POST JSON body:
json
Copy code
{
"title": "Gynecologist in Thessaloniki | Dr. Example",
"description": "Trusted specialist in fertility and pregnancy care.",
"focus": "fertility doctor Thessaloniki"
}
Permission is limited to users with capability edit_post on the given post.
✅ Testing Checklist
Activate the plugin → verify that /wp-content/mu-plugins/rankmath-rest-api.php is created.
Visit Settings → Rank Math API → verify MU plugin status indicators.
Toggle endpoint checkboxes → save settings → confirm persistence.
Use “Reinstall MU Plugin” button → confirm backup file creation.
Test REST endpoints using cURL or Postman.
Run lint checks:
PowerShell
powershell
Copy code
.\tests\run-lint.ps1 -MuFile "C:\path\to\wordpress\wp-content\mu-plugins\rankmath-rest-api.php"
PHP CLI
bash
Copy code
php tests/check_mu_syntax.php C:\path\to\wordpress\wp-content\mu-plugins\rankmath-rest-api.php
🧰 Developer Notes
The MU plugin is not removed on deactivation — by design, so automation workflows don’t break.
Security uses native WordPress capabilities and REST permissions.
Rank Math SEO plugin must be active for these meta keys to exist.
Works with WordPress 6.4+ and Rank Math 1.0.213+.
🧑💻 Credits
Developed by:
🧠 Valandi Angelidis
Multidisciplinary creator & full-stack developer specializing in digital ecosystems, automation, and medical marketing technologies.
🌐 Website: valandiangelidis.com
💌 Email: info@valandiangelidis.com
💾 GitHub: github.com/ValandiAngelidis
📜 License
Licensed under the GNU General Public License v2.0 (GPL-2.0+).
You are free to use, modify, and distribute this software under the same license.
🚀 Future Enhancements (Planned)
Automatic Application Password generator for easier API setup.
Inline endpoint tester within the Settings page.
REST schema documentation in the WordPress REST API index.
Unit tests via WP-CLI or WordPress Test Harness.
⭐ Contribute
If you’d like to improve or extend this plugin, feel free to fork the repository and submit a pull request at:
👉 https://github.com/ValandiAngelidis/rankmath-rest-api-enabler
---
✅ **You can now copy and paste this file as-is** into your GitHub repo root (`README.md`).
GitHub will render it beautifully with emoji sections, links, and syntax highlighting.