AI
Wordpress
AI SEO Content Quality Analyzer for WordPress Using PHP and OpenAI
I've used Yoast and Rank Math for years. Both are solid, but they kept telling me what was wrong, keyword density too low, meta too long without ever telling me why the content wasn't ranking. So I built something different.
This tutorial walks through building a WordPress plugin that uses OpenAI to analyze your post content the way a search engine actually thinks about it, checking search intent alignment, content depth, and semantic quality then gives you a score and specific suggestions right inside the post editor.
Once installed, the plugin analyzes each post and:
- Analyze the alignment of search intent
- Verify the content's completeness
- Identify generic or thin sections
- Examine the quality of semantic SEO
- Make suggestions for headings, FAQs, and enhancements
- Give an AI SEO score between 0 and 100.
This is much more advanced than conventional SEO plugins.
Requirements
- WordPress 6.x
- PHP 8.1+
- Composer (optional)
- An OpenAI API key
- Basic WordPress plugin development knowledge
Step 1: Create the WordPress Plugin
Create a new plugin folder:
wp-content/plugins/ai-seo-analyzer/
Create ai-seo-analyzer.php
/**
* Plugin Name: AI SEO Content Quality Analyzer
* Description: Analyzes WordPress content quality using AI and provides SEO recommendations.
* Version: 1.0.0
* Author: phpcmsframework.com
*/
if (!defined('ABSPATH')) exit;
Activate the plugin from WP Admin → Plugins.
Step 2: Add Meta Box in Post Editor
add_action('add_meta_boxes', function () {
add_meta_box(
'ai_seo_box',
'AI SEO Content Analyzer',
'ai_seo_meta_box',
['post', 'page'],
'side',
'high'
);
});
function ai_seo_meta_box($post)
{
echo '<button class="button button-primary" id="ai-seo-analyze">Analyze Content</button>';
echo '<div id="ai-seo-result" style="margin-top:10px;"></div>';
}
Step 3: AJAX Handler (PHP Only)
add_action('wp_ajax_ai_seo_analyze', 'ai_seo_analyze');
function ai_seo_analyze()
{
$postId = intval($_POST['post_id']);
$post = get_post($postId);
if (!$post) {
wp_send_json_error('Post not found');
}
$analysis = ai_seo_analyze_content($post->post_title, $post->post_content);
wp_send_json_success($analysis);
}
Step 4: AI Content Analysis Function
function ai_seo_analyze_content($title, $content)
{
$prompt = "
Analyze the SEO quality of the following content.
Return JSON with:
- seo_score (0-100)
- intent_match (Good/Average/Poor)
- strengths (list)
- weaknesses (list)
- improvement_suggestions (list)
- suggested_headings
- suggested_faqs
Title:
$title
Content:
" . strip_tags($content);
$payload = [
'model' => 'gpt-4o-mini',
'messages' => [
['role' => 'system', 'content' => 'You are an expert SEO auditor.'],
['role' => 'user', 'content' => $prompt]
],
'temperature' => 0.2
];
$ch = curl_init('https://api.openai.com/v1/chat/completions');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . getenv('OPENAI_API_KEY')
],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload)
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return json_decode($response['choices'][0]['message']['content'], true);
}
Step 5: JavaScript for Admin UI
add_action('admin_footer', function () {
?>
<script>
jQuery(function ($) {
$('#ai-seo-analyze').on('click', function () {
$('#ai-seo-result').html('Analyzing...');
$.post(ajaxurl, {
action: 'ai_seo_analyze',
post_id: $('#post_ID').val()
}, function (res) {
if (res.success) {
let r = res.data;
$('#ai-seo-result').html(`
<strong>SEO Score:</strong> ${r.seo_score}/100<br><br>
<strong>Strengths:</strong><ul>${r.strengths.map(i => `<li>${i}</li>`).join('')}</ul>
<strong>Weaknesses:</strong><ul>${r.weaknesses.map(i => `<li>${i}</li>`).join('')}</ul>
`);
} else {
$('#ai-seo-result').html('Error analyzing content.');
}
});
});
});
<?php
});
How It Works (Editor View)
- Open any post or page
- Click “Analyze Content”
- AI reviews search intent, depth, structure
- You get a quality score + fixes
- Update content → re-analyze
Smart Enhancements You Can Add
- Compare against top-ranking competitor URLs
- Detect keyword stuffing vs natural language
- Analyze internal linking opportunities
- Auto-generate missing sections
- Save score history per post
- Bulk audit via WP-CLI
Security & Performance Notes
- Store API key in wp-config.php
- Limit analysis frequency
- Strip shortcodes before sending content
- Cache analysis results
- Use nonces for AJAX calls in production
PHP CMS Frameworks
January 27, 2026
Read more →
No more posts to load.
About this blog
PHPCMSFramework.com
Tutorials for WordPress, Laravel, Drupal, Joomla, Symfony & more — including AI-powered PHP guides. Publishing since 2012.
Trending posts
- Steps to create a Contact Form in Symfony With SwiftMailer
- Building a RAG System in Laravel from Scratch
- Build a WhatsApp AI Assistant Using Laravel, Twilio and OpenAI
- Laravel and Prism PHP: The Modern Way to Work with AI Models
- CIBB - Basic Forum With Codeigniter and Twitter Bootstrap
- Drupal 7 - Create your custom Hello World module
- Build an AI Code Review Bot with Laravel — Real-World Use Case
- Create Front End Component in Joomla - Step by step procedure
- Symfony Framework - Introduction
- A step by step procedure to develop wordpress plugin