Skip to content

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.

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”
site/ready.php
<?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;
}
});

Synchronize Template Rules (seo-mappings) and optionally create or attach an embedded FieldtypeEntries SEO field:

Terminal window
# Preview changes without modifying templates or rules
php vendor/bin/wire seo:setup --field=metadata --templates=home,page --dry-run --json
# Attach metadata field and include templates that have no pages yet
php 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.

Inspect environment mode, attached SEO fields, average readiness score, active Template Rules, Redirects, 404 Monitor logs, and public crawler manifests:

Terminal window
php vendor/bin/wire seo:audit --json

List active redirect rules, upsert a single rule, promote a 404 Monitor entry, or bulk-import a CSV file:

Terminal window
# List rules
php vendor/bin/wire seo:redirect --json
# Upsert a redirect rule
php vendor/bin/wire seo:redirect --from="/old-fleet/" --to="/fleet/" --code=301 --match=exact --json
# Promote a 404 log UUID to a 301 redirect
php 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.

Pages Emit noindex, nofollow in Production

Section titled “Pages Emit noindex, nofollow in Production”
  • Run php vendor/bin/wire seo:audit and inspect Environment Mode.
  • If environment is set to staging, local, or auto while $config->debug = true, switch Environment Mode to live under Setup -> SEO -> Settings -> General & Titles (or set $config->debug = false in site/config.php).
  • $seo->render($page) already renders <head> scripts (GTM, GA4, Meta Pixel, scripts_head). If you call $seo->renderScripts('head') manually, pass includeHeadScripts: false to $seo->render($page, includeHeadScripts: false).

Redirects Do Not Fire for an Existing Page

Section titled “Redirects Do Not Fire for an Existing Page”
  • RedirectEngine runs on ProcessPageView::pageNotFound by 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.
  • Call $seo->invalidateContentCaches() (which clears SitemapGenerator and SeoScoreAnalyzer caches) after direct database imports.

Next steps