Overview
TheKeyword_Analyzer class analyzes content for focus keyword optimization, checking keyword placement, density, and distribution throughout the content. It provides a comprehensive scoring system based on SEO best practices.
Namespace: GeoAI\Analyzers
File: includes/analyzers/class-keyword-analyzer.php
Purpose
The Keyword Analyzer evaluates how well a focus keyword is optimized within content by checking:- Keyword presence in title, meta description, URL slug, and first paragraph
- Keyword density (ideal range: 0.5% - 2.5%)
- Keyword distribution across content sections
- Position of keyword within title (bonus for early placement)
Scoring Algorithm
The analyzer uses a weighted scoring system with a maximum of 100 points:| Component | Points | Description |
|---|---|---|
| Keyword in Title | 20 | Full points if in title, bonus if at beginning |
| Keyword in Meta Description | 15 | Checks meta description for keyword presence |
| Keyword in URL Slug | 10 | Validates keyword in post slug |
| Keyword in First Paragraph | 15 | Ensures keyword appears early in content |
| Keyword Density | 20 | Optimal range: 0.5% - 2.5% |
| Keyword Distribution | 20 | Checks presence across 3 content sections |
Density Thresholds
- < 0.3%: Too low (5 points, warning)
- 0.3% - 3.0%: Optimal (20 points)
- > 3.0%: Too high, keyword stuffing (5 points, error)
Public Methods
analyze()
Analyzes content for focus keyword optimization.The focus keyword to analyze
Content data array containing:
title(string): Post titlecontent(string): Post contentexcerpt(string): Post excerptslug(string): Post URL slugmeta_description(string): Meta description
array - Analysis results
Return Structure:
Usage Examples
Basic Analysis
Displaying Issues
Checking Specific Criteria
Integration in Post Editor
Issue IDs Reference
| Issue ID | Severity | Description |
|---|---|---|
no_keyword | error | No focus keyword provided |
keyword_not_in_title | error | Keyword missing from title |
keyword_in_title | good | Keyword found in title |
keyword_in_title_start | good | Keyword at beginning of title |
no_meta_description | warning | No meta description set |
keyword_not_in_meta | warning | Keyword not in meta description |
keyword_in_meta | good | Keyword in meta description |
keyword_not_in_slug | warning | Keyword not in URL slug |
keyword_in_slug | good | Keyword in URL slug |
keyword_not_in_first_para | warning | Keyword not in first paragraph |
keyword_in_first_para | good | Keyword in first paragraph |
keyword_density_low | warning | Density < 0.3% |
keyword_density_good | good | Density 0.3% - 3.0% |
keyword_density_high | error | Density > 3.0% |
keyword_not_distributed | error | Keyword not found in content |
keyword_poorly_distributed | warning | Keyword in 1 of 3 sections |
keyword_fairly_distributed | ok | Keyword in 2 of 3 sections |
keyword_well_distributed | good | Keyword in all 3 sections |
Best Practices
- Title Optimization: Place keyword at the beginning of titles for maximum impact (20 points vs 15 points)
- Density Range: Aim for 0.5% - 2.5% keyword density to avoid penalties
- Natural Distribution: Ensure keyword appears throughout content, not just in one section
- Avoid Keyword Stuffing: Density above 3.0% may be flagged as spam
- First Paragraph: Include keyword early to establish topic relevance