Anansi SEO developer docs

This folder is for theme and plugin developers who want to extend Anansi SEO or integrate with it, and for site builders who move custom code over from Rank Math or Yoast SEO. It covers how the plugin is organised, its filters and actions, the PHP functions themes can call, the WP-CLI commands, the REST routes and Abilities, and how to move existing code. Everything here was written against Anansi SEO 0.5.11 and taken from the source code.

Contents

FileWhat it covers
hooks.mdEvery public filter and action, grouped by feature, plus the Rank Math hooks Anansi fires for compatibility.
functions.mdanansi_is_active(), breadcrumb functions and shortcodes, meta keys and how to read them.
cli.mdAll wp anansi … commands with options and examples.
rest-and-abilities.mdREST routes under anansi/v1 and the two WordPress Abilities.
migration-for-developers.mdMoving custom code from Rank Math or Yoast SEO, and what uninstall removes.
theme-integration.mdHow a theme steps aside and feeds its own data to Anansi, with full examples.

How Anansi is organised

Modes: preview and live

Anansi has two modes, stored in the anansi_mode option.

  • preview (the default on a new install). Anansi prints nothing for visitors. A signed preview request (a URL with ?anansi_preview=<key>, made by the admin dashboard or by wp anansi preview) shows what Anansi would print, between <!-- anansi-preview --> and <!-- /anansi-preview --> markers, next to what the page prints today. Preview responses are sent with no-cache headers and X-Robots-Tag: noindex, nofollow.
  • live. Anansi prints its head tags, schema and sitemaps, and runs its redirects.

Switch modes in the dashboard or with wp anansi mode live.

What “in charge” means

Anansi is in charge when the mode is live and no other full SEO plugin is active. The plugins that block it are Rank Math, Yoast SEO, All in One SEO, SEOPress and The SEO Framework. Even in live mode, Anansi waits while one of them is active, so the same tags are never printed twice.

StateAnansi prints for visitorsanansi_is_active()
Preview modeNofalse
Live mode, another SEO plugin activeNofalse
Live mode, no other SEO pluginYestrue
Signed preview requestOnly on that request, between markersfalse

Themes and plugins should call anansi_is_active() to decide whether to step aside. Most anansi/… filters on page output only run when Anansi builds that output: when it is in charge, or on a signed preview request.

Modules

Core output lives in includes/ and always loads: head block, meta tags, Open Graph, schema, primary term, news sitemap and video schema. Other features are modules, one folder each under includes/modules/{slug}/:

ModuleFeature
abilitiesWordPress Abilities API (read and update a post’s SEO fields).
blocksRank Math FAQ/HowTo block support and the Google preferred-source link.
crawlersrobots.txt, AI crawler rules, llms.txt, IndexNow, site verification tags.
editorSEO panel in the block editor, classic meta box, term and user fields, list columns.
googleGoogle Search Console and YouTube Data API connection.
last-updatedOptional “Last updated” line in post content (settings in anansi_titles, last_updated_* keys).
importImporters, migration snapshots, settings export/import, breadcrumb compatibility shims.
linksInternal link suggestions.
redirectsRedirects and the 404 log.
sitemapsXML sitemaps, image sitemaps, HTML sitemap, sitemap cache.
tweaksLock modified date, category base, attachment redirects, link attributes, RSS footer.

Each module’s module.php returns its main object. Class files load only when first used.

Head output

Anansi prints one block in wp_head at priority 1:

<!-- Anansi SEO -->
<title>…</title>
<meta name="description" … />
…
<script type="application/ld+json" class="anansi-schema">…</script>
<!-- /Anansi SEO -->

Tags come from the anansi/head/tags filter. Schema and other blocks are printed on the anansi/head action. In live mode Anansi removes WordPress’s own title, robots and canonical output. See hooks.md.

Read-through meta

Anansi can run on a site without a data migration. When it reads a post, term or user field it tries, in order:

  1. _anansi_{key} (Anansi’s own meta).
  2. rank_math_{key} (Rank Math’s meta; for news_robots the key is rank_math_news_sitemap_robots).
  3. Any keys added with the anansi/meta/sources filter.

The first stored, non-empty value wins. For text fields (title, description, canonical URL and similar), an empty string saved under the _anansi_ key means “cleared on purpose” and stops the read-through. Anansi writes only to _anansi_* keys. It never changes or deletes another plugin’s data. See functions.md.

Options

Settings use Rank Math’s key names inside Anansi’s own options, so a site moved from Rank Math keeps every value. Boolean settings follow Rank Math’s 'on' / 'off' style.

OptionHolds
anansi_modepreview or live.
anansi_preview_keySecret for signed preview requests.
anansi_titlesTitles & Meta and Social settings (Rank Math’s rank-math-options-titles keys).
anansi_generalGeneral settings: breadcrumbs, links, images, feeds, redirects, verification (Rank Math’s rank-math-options-general keys).
anansi_sitemapSitemap settings (Rank Math’s rank-math-options-sitemap keys).
anansi_settingsNews sitemap and video settings.
anansi_videoExtra video schema settings.
anansi_blocksPreferred-source block settings.
anansi_crawlersrobots.txt, AI crawler, llms.txt and IndexNow settings.
anansi_linksInternal link suggestion settings.
anansi_abilitiesThe Abilities on/off switch (enabled).
anansi_googleGoogle connection settings.

Read settings through the classes (Anansi_Titles::get( $key ), Anansi_General::get( $key )) rather than the raw option when you can. Both return Rank Math-normalised values ('on' becomes true).

Anansi also creates its own tables: {prefix}anansi_redirects, {prefix}anansi_redirects_index, {prefix}anansi_redirects_index_b, {prefix}anansi_404_log and {prefix}anansi_link_vectors. Their layout is internal.

Rank Math compatibility hooks

Many anansi/… filters have a matching rank_math/… filter that Anansi fires with the same arguments, so theme and plugin code written for Rank Math keeps working after the switch. Anansi fires the Rank Math name only when Rank Math is not active (and for most hooks also on a signed preview request). See hooks.md.

Stability

The hooks, functions, commands and routes documented here are intended to stay. Undocumented hooks, classes and methods may change between releases. Where a hook below is marked low-level or internal, treat it the same way.

Anansi is before version 1.0. If a documented hook has to change, the change will be listed in readme.txt under the version that makes it.

Requirements

  • WordPress 6.2 or later (the Abilities need 6.9 or later).
  • PHP 7.4 or later.
  • Text domain: anansi-seo. Prefixes: anansi_, Anansi_, ANANSI_, hooks anansi/….