Files
advanced-seo-keywords/README.md
T
mydev 5837c330d0
Build WordPress Plugin (XML-driven) / build-release (push) Failing after 3m26s
provide new features
2026-11-23 10:22:56 +02:00

317 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Advanced SEO Meta + AI FAQ Schema
A lightweight WordPress plugin for precise control over page titles, meta descriptions, Open Graph / Twitter cards, canonical and robots tags, FAQ structured data, and business (local) schema.
[![Version](https://img.shields.io/badge/version-4.1.0-blue.svg)](#changelog)
[![WordPress](https://img.shields.io/badge/wordpress-5.7%2B-brightgreen.svg)](#requirements)
[![PHP](https://img.shields.io/badge/php-7.4%2B-8892BF.svg)](#requirements)
[![License](https://img.shields.io/badge/license-GPL--2.0%2B-lightgrey.svg)](#license)
## Table of contents
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Upgrading from 3.x](#upgrading-from-3x)
- [Usage](#usage)
- [Settings](#settings)
- [FAQ schema and the `[seo_faq]` shortcode](#faq-schema-and-the-seo_faq-shortcode)
- [What gets output on the front end](#what-gets-output-on-the-front-end)
- [Compatibility with other SEO plugins](#compatibility-with-other-seo-plugins)
- [Developer reference](#developer-reference)
- [Troubleshooting](#troubleshooting)
- [Uninstalling](#uninstalling)
- [Changelog](#changelog)
- [License](#license)
## Features
**Per-post / per-page (meta box)**
- Custom SEO title and meta description, with live character counters (title ~60, description 150–160)
- Social share image (`og:image`) override, with fallback to Featured Image, then the site default
- "Hide from search engines" (noindex) checkbox, which also removes the item from the core XML sitemap
- FAQ builder: drag-to-reorder rows, duplicate-question warning, basic HTML allowed in answers
- Works on every public post type (filterable)
**Site-wide (Settings → Advanced SEO)**
- Homepage title and description
- Default Open Graph image (1200×630 recommended)
- Business schema: `MedicalBusiness`, `MedicalClinic`, `DiagnosticLab`, `LocalBusiness` or `Organization`, with address, phone, email, geo, opening hours, price range, areas served and `sameAs` profiles
**Front-end output**
- `<title>` override
- Meta description (one shared source for both `description` and `og:description`, trimmed at a word boundary to 160 characters)
- Canonical URL (replaces the core one, pagination-aware)
- Robots: `noindex` for search, 404 and flagged posts (via the core `wp_robots` filter)
- Open Graph and Twitter Card tags, including `article:*` tags for posts
- FAQPage JSON-LD and a visible `[seo_faq]` shortcode
- Business JSON-LD on the homepage
- Handles static front pages and separate posts pages correctly, plus category, tag, taxonomy and author archives
## Requirements
- WordPress 5.7 or later (uses the `wp_robots` filter)
- PHP 7.4 or later
## Installation
**From a ZIP**
1. Download the latest ZIP from [Releases](https://git.my-dev.pro/mydev/advanced-seo-keywords/releases).
2. In WordPress go to **Plugins → Add New → Upload Plugin**, choose the ZIP and click **Install Now**.
3. Click **Activate**.
**Manually**
1. Copy the plugin folder to `wp-content/plugins/advanced-seo-keywords/` (the main file is `advanced-seo-keywords.php`).
2. Activate it under **Plugins → Installed Plugins**, or run `wp plugin activate advanced-seo-keywords`.
After activation:
- Go to **Settings → Advanced SEO** and fill in the homepage and business details.
- Edit any post or page to see the **Advanced SEO & FAQ Schema** meta box.
## Upgrading from 3.x
Version 3.x and 4.x define the same PHP class (`Advanced_SEO_Meta`), so they cannot be active at the same time.
1. Replace the plugin files in the **same folder** (`advanced-seo-keywords`), or deactivate and delete the old 3.x plugin first and then install 4.x.
2. Activate the plugin and confirm that **Settings → Advanced SEO** now exists.
3. Clear your caches (object cache, page cache and CDN).
Your existing data is preserved. Version 4.x reads the same post meta keys (`_seo_title`, `_seo_description`, `_seo_faq`) as 3.x.
> **Note:** the 3.x README listed `aseo_*` filters. Those were never implemented in the 3.x code. Use the `advanced_seo_*` filters documented [below](#developer-reference).
## Usage
### Per post or page
1. Open the editor and find the **Advanced SEO & FAQ Schema** box.
2. Fill in:
- **SEO Title** (counter turns green between 30 and 60 characters)
- **Meta Description** (green between 120 and 160 characters)
- **Noindex** if the page should stay out of search results and the sitemap
- **Social Share Image** (1200×630 recommended)
- **FAQ** question and answer pairs
3. Update the post.
If a field is empty, the plugin falls back sensibly:
| Value | Fallback chain |
|---|---|
| Title | Custom title → WordPress default title |
| Description | Custom description → manual excerpt → trimmed content (shortcodes and blocks stripped) |
| `og:image` | Per-post image → Featured Image → Default OG Image → Site Icon |
### Homepage
Set the homepage title, description and default OG image under **Settings → Advanced SEO**. If those are blank, the static front page's own SEO fields are used, then the site title and tagline.
## Settings
**Settings → Advanced SEO**
| Section | Field | Notes |
|---|---|---|
| Homepage SEO | Title | ~60 characters |
| | Meta Description | 150–160 characters |
| | Default OG Image | Used when a page has no image of its own |
| Business Schema | Schema Type | `MedicalBusiness`, `MedicalClinic`, `DiagnosticLab`, `LocalBusiness`, `Organization` |
| | Business Name | Leave blank to disable the schema entirely |
| | Phone, Email | |
| | Street, City, Country (2-letter code) | Output as `PostalAddress` |
| | Latitude, Longitude | Output as `GeoCoordinates` |
| | Opening Hours | One per line, e.g. `Mo-Fr 09:00-17:00` |
| | Price Range | e.g. `$$` |
| | Areas Served | Comma-separated codes, output as `Country` objects |
| | Social / Profile URLs | One per line, output as `sameAs` |
| | Logo | Output as `logo` and `image` |
Business schema is printed on the homepage only (first page, not paginated).
## FAQ schema and the `[seo_faq]` shortcode
The meta box stores question and answer pairs and prints them as `FAQPage` JSON-LD in the page head.
Google requires FAQ markup to match content that is **visible on the page**. Display the same Q&As with the shortcode:
```
[seo_faq]
```
Or for a specific post:
```
[seo_faq id="123"]
```
In a template:
```php
echo do_shortcode( '[seo_faq]' );
```
The shortcode renders this markup, which you can style:
```html
<div class="advanced-seo-faq">
<div class="advanced-seo-faq__item">
<h3 class="advanced-seo-faq__question">…</h3>
<div class="advanced-seo-faq__answer">…</div>
</div>
</div>
```
Allowed HTML in answers: `p`, `br`, `ul`, `ol`, `li`, `strong`, `b`, `em`, `i`, `a[href]` and headings `h2`–`h6`.
> **About rich results:** since August 2023, Google shows FAQ rich results only for well-known government and health authority sites. The markup remains valid structured data, but do not expect expanded FAQ listings for most sites, and there is no verified evidence that it influences AI-generated answers.
## What gets output on the front end
| Tag | Source |
|---|---|
| `<title>` | `pre_get_document_title` filter |
| `<meta name="description">` | Shared description resolver |
| `<link rel="canonical">` | Own output; core `rel_canonical` is removed |
| `<meta name="robots">` | Core `wp_robots` filter (adds `noindex` where needed) |
| `og:*`, `article:*`, `twitter:*` | Open Graph block (look for the `Advanced SEO Meta: Open Graph` HTML comment) |
| FAQPage JSON-LD | Singular pages with FAQ entries |
| Business JSON-LD | Homepage, when a Business Name is set |
Noindex is applied to search results, 404 pages and posts flagged in the meta box. Paginated archives stay indexable by default (see the `advanced_seo_noindex_paginated` filter).
## Compatibility with other SEO plugins
To avoid duplicate tags, the plugin detects Yoast SEO, Rank Math, All in One SEO, SEOPress and The SEO Framework. When one is active:
- the title, description, Open Graph, canonical and robots output is turned off,
- FAQ and business schema are still printed,
- an admin notice appears on the Plugins page and on the settings page.
Override this with the `advanced_seo_force_output` filter.
## Developer reference
### Filters
| Filter | Arguments | Purpose |
|---|---|---|
| `advanced_seo_post_types` | `array $post_types` | Post types that get the meta box and REST fields (default: all public types except attachments) |
| `advanced_seo_og_data` | `array $data` | Modify Open Graph data before output |
| `advanced_seo_business_schema` | `array $schema` | Modify the business schema array, e.g. add a second location |
| `advanced_seo_canonical` | `string $url, array $ctx` | Modify the canonical URL |
| `advanced_seo_noindex_paginated` | `bool $noindex` (default `false`) | Return `true` to noindex paginated archives |
| `advanced_seo_force_output` | `bool $force` (default `false`) | Return `true` to keep frontend output even if another SEO plugin is active |
Examples:
```php
// Limit the plugin to posts and pages only.
add_filter( 'advanced_seo_post_types', function () {
return [ 'post', 'page' ];
} );
// Add a second business location.
add_filter( 'advanced_seo_business_schema', function ( $schema ) {
$schema['location'] = [
[ '@type' => 'Place', 'name' => 'Dubai branch',
'address' => [ '@type' => 'PostalAddress',
'streetAddress' => 'Dubai Silicon Oasis, DDP, Building A2',
'addressLocality' => 'Dubai', 'addressCountry' => 'AE' ] ],
];
return $schema;
} );
// Set a custom OG image for a specific page.
add_filter( 'advanced_seo_og_data', function ( $data ) {
if ( is_page( 'contact' ) ) {
$data['image'] = 'https://example.com/contact-og.jpg';
}
return $data;
} );
```
### Post meta
| Key | Type | Description |
|---|---|---|
| `_seo_title` | string | SEO title |
| `_seo_description` | string | Meta description |
| `_seo_og_image_id` | int | Attachment ID for `og:image` |
| `_seo_faq` | array | `[ [ 'question' => '…', 'answer' => '…' ], … ]` |
| `_seo_noindex` | string | `'1'` when the post is noindexed |
These keys are exposed through the REST API (`show_in_rest`), so they are available to the block editor and external tools.
### Options
`_seo_home_title`, `_seo_home_description`, `_seo_default_og_image`, `_seo_biz_type`, `_seo_biz_name`, `_seo_biz_phone`, `_seo_biz_email`, `_seo_biz_street`, `_seo_biz_city`, `_seo_biz_country`, `_seo_biz_areas`, `_seo_biz_logo`, `_seo_biz_sameas`, `_seo_biz_lat`, `_seo_biz_lng`, `_seo_biz_hours`, `_seo_biz_price`
### Image size
A hard-cropped `advanced_seo_og` size (1200×630) is registered. Regenerate thumbnails for existing images to benefit from it; until then the full-size image is used.
## Troubleshooting
**Settings → Advanced SEO does not appear**
The 4.x code is not running. Confirm that the plugin is active and that no other copy defines `Advanced_SEO_Meta` (`grep -rl "Advanced_SEO_Meta" wp-content --include=*.php`). Flush the object cache and ask your host to reset PHP opcache if the file on disk was just replaced.
**The page still shows only four OG tags and `og:type=article`**
That is the 3.x output. See [Upgrading from 3.x](#upgrading-from-3x).
**Duplicate title, description or OG tags**
Another SEO plugin, the theme or a code snippet is printing them as well. Disable one source.
**No `og:image` on shares**
Set a Default OG Image under Settings → Advanced SEO, and clear the Facebook / LinkedIn sharing debugger caches.
**FAQ rich results do not appear**
See the note [above](#faq-schema-and-the-seo_faq-shortcode); this is a Google policy and not a plugin fault. Validate the markup with Google's Rich Results Test.
## Uninstalling
Deleting the plugin from **Plugins → Installed Plugins** removes all of its options and all `_seo_*` post meta (titles, descriptions, images, FAQs and noindex flags). Back up your database first if you may reinstall later. Deactivating the plugin does not delete anything.
## Changelog
### 4.1.0
- Fix: static front page and posts page are handled separately, so the posts page no longer inherits homepage SEO
- Fix: one shared description resolver for `description` and `og:description`; shortcodes and blocks stripped; trimmed at a word boundary
- Fix: schema JSON encoded with `JSON_HEX_TAG` and `JSON_HEX_AMP`
- Fix: saving skips revisions and unsupported post types; empty values are deleted instead of stored
- Fix: OG data filter result merged with defaults to avoid PHP notices
- New: canonical URL output (replaces the core one) and robots handling via `wp_robots`
- New: per-post noindex checkbox and exclusion from the XML sitemap
- New: detection of Yoast, Rank Math, AIOSEO, SEOPress and The SEO Framework
- New: `[seo_faq]` shortcode for the visible FAQ; basic HTML preserved in FAQ answers
- New: business schema types, `@id`, `logo`, `email`, `geo`, `openingHours`, `priceRange`, `sameAs`, `Country` objects for `areaServed`
- New: 1200×630 cropped OG image size
- New: support for all public post types and for term and author archives
- New: character counters, drag-to-reorder FAQ rows, duplicate-question warning
- New: REST / block editor exposure of the SEO meta fields
- New: translation loading, uninstall cleanup, `Requires PHP` and `Requires at least` headers
### 4.0.0
- New: Settings page (homepage title and description, default OG image)
- New: per-post `og:image` override with Featured Image and default fallbacks
- New: Twitter Card tags
- New: `MedicalBusiness` JSON-LD on the homepage
- New: media picker for images
### 3.0.0
- Initial release: SEO title, meta description, Open Graph, FAQ builder and FAQPage JSON-LD
## Support
Open an issue in the [repository](https://git.my-dev.pro/mydev/advanced-seo-keywords/issues) for bugs and feature requests.
## License
GPL-2.0-or-later. See the plugin header for details.