Plugins for SEO tell you what needs to be fixed, but not why.
They look at readability scores, keyword density, and meta length, but they totally ignore search intent, semantic depth, and content quality.
In this tutorial, we'll use PHP and OpenAI to create an AI-powered SEO Content Quality Analyzer for WordPress.
AI will assess content in the same manner as a search engine rather than according to strict guidelines.
Real-time post analysis and actionable SEO feedback are provided by this tool, which operates within WordPress Admin.
For every post, the system will:
- 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
Next up, we’ll build a AI Content Pruning Tool for Symfony.
0 comments:
Post a Comment