PHP API, Hooks & CLI
For the complete class and method dictionary (SeoBag, SeoResolver, SchemaBuilder, RedirectEngine, SitemapGenerator), read site/modules/Seo/API.md or run php index.php docs get-text Seo. This page covers the hooks, CLI commands, and operational checks you use daily.
Hookable Methods (Seo & ProcessSeo)
Section titled “Hookable Methods (Seo & ProcessSeo)”| Hook | Arguments & Return | Timing | What It Does |
|---|---|---|---|
Seo::resolve |
(?Page $page = null, ?EntryItem $entry = null, array $overrides = [], ?Language $language = null, bool $resizeImages = true): SeoBag |
After | Resolves the SeoBag (meta tags, Open Graph, Twitter cards, canonical, robots, and JSON-LD) before the priority-9999 finalizer runs. |
Seo::render |
(?Page $page = null, ?EntryItem $entry = null, array $overrides = [], bool $includeHeadScripts = true): string |
Before / After | Renders the final <head> HTML tags and optional analytics scripts. |
Seo::resolveBlueprint |
(string $type, array $definition): array |
After | Extends internal seo-* Entries blueprint definitions (for example adding custom fields to seo-mappings). |
ProcessSeo::translations |
(): array |
After | Returns localized UI strings for the Setup -> SEO React workspace. |
Add Custom Meta Tags & Extend an Internal SEO Blueprint
Section titled “Add Custom Meta Tags & Extend an Internal SEO Blueprint”<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Seo\Bag\SeoBag;
$wire->addHookAfter('Seo::resolve', function (HookEvent $event): void { $bag = $event->return; $page = $event->arguments(0); if (!$bag instanceof SeoBag || !$page instanceof Page) { return; }
if ($page->template->name === 'yacht') { $bag->meta()->setExtraMeta('charter-region', 'Aegean'); }});
$wire->addHookAfter('Seo::resolveBlueprint', function (HookEvent $event): void { $type = (string) $event->arguments(0); $definition = (array) $event->return;
if ($type === 'seo-mappings') { $definition['fields']['editorial_owner'] = [ 'type' => 'text', 'label' => 'Editorial Owner', ]; $event->return = $definition; }});CLI Commands (php vendor/bin/wire)
Section titled “CLI Commands (php vendor/bin/wire)”1. seo:setup
Section titled “1. seo:setup”Synchronize Template Rules (seo-mappings) and optionally create or attach an embedded FieldtypeEntries SEO field:
# Preview changes without modifying templates or rulesphp vendor/bin/wire seo:setup --field=metadata --templates=home,page --dry-run --json
# Attach metadata field and include templates that have no pages yetphp vendor/bin/wire seo:setup --field=metadata --templates=home,page --all-templates --json| Flag | Behavior |
|---|---|
--field=<name> |
Create or verify an embedded FieldtypeEntries SEO field (defaults to metadata). |
--templates=<list> |
Comma-separated ProcessWire template names to attach the SEO field to. |
--all-templates |
Include eligible frontend templates that do not yet have a template file or pages. |
--dry-run |
Validate targets and preview actions without writing. |
--json |
Output structured JSON. |
2. seo:audit
Section titled “2. seo:audit”Inspect environment mode, attached SEO fields, average readiness score, active Template Rules, Redirects, 404 Monitor logs, and public crawler manifests:
php vendor/bin/wire seo:audit --json3. seo:redirect
Section titled “3. seo:redirect”List active redirect rules, upsert a single rule, promote a 404 Monitor entry, or bulk-import a CSV file:
# List rulesphp vendor/bin/wire seo:redirect --json
# Upsert a redirect rulephp vendor/bin/wire seo:redirect --from="/old-fleet/" --to="/fleet/" --code=301 --match=exact --json
# Promote a 404 log UUID to a 301 redirectphp vendor/bin/wire seo:redirect --promote-404=<uuid> --to="/destinations/gocek/" --code=301 --json
# Import CSV rules (dry-run first)php vendor/bin/wire seo:redirect --import=site/modules/Seo/examples/real-world/redirects.csv --dry-run --json| Flag | Values / Behavior |
|---|---|
--from=<path> |
Source path, wildcard, or regex pattern (mutually exclusive with --promote-404 and --import). |
--to=<url> |
Destination path or absolute URL (optional when --code=410). |
--code=<code> |
HTTP status code: 301, 302, 307, 308, or 410 (default 301). |
--match=<type> |
Match type: exact, wildcard, or regex (default exact). |
--promote-404=<uuid> |
Promote an unresolved seo-404s UUID to an exact redirect pointing to --to. |
--import=<file> |
Import rules from a .csv or .txt file (max 5 MB / 5,000 rows). |
--dry-run |
Validate inputs or CSV rows without persisting changes. |
--json |
Output structured JSON. |
Troubleshooting
Section titled “Troubleshooting”Pages Emit noindex, nofollow in Production
Section titled “Pages Emit noindex, nofollow in Production”- Run
php vendor/bin/wire seo:auditand inspectEnvironment Mode. - If
environmentis set tostaging,local, orautowhile$config->debug = true, switch Environment Mode toliveunder Setup -> SEO -> Settings -> General & Titles (or set$config->debug = falseinsite/config.php).
Duplicate Analytics Scripts in <head>
Section titled “Duplicate Analytics Scripts in <head>”$seo->render($page)already renders<head>scripts (GTM,GA4,Meta Pixel,scripts_head). If you call$seo->renderScripts('head')manually, passincludeHeadScripts: falseto$seo->render($page, includeHeadScripts: false).
Redirects Do Not Fire for an Existing Page
Section titled “Redirects Do Not Fire for an Existing Page”RedirectEngineruns onProcessPageView::pageNotFoundby design so live pages incur zero overhead. If a published ProcessWire page still exists at/old-fleet/, unpublish, rename, or delete the page so ProcessWire delegates to the redirect rule.
Stale Sitemap or Health Score Cache
Section titled “Stale Sitemap or Health Score Cache”- Call
$seo->invalidateContentCaches()(which clearsSitemapGeneratorandSeoScoreAnalyzercaches) after direct database imports.