Skip to content

[00] Subset SEO, For developers

Developer reference

Template variables, the filters on every tag, adding schema pieces and sitemaps, breadcrumbs, the meta keys, REST and WP-CLI.

Every tag Subset SEO prints, every template variable, schema piece, sitemap entry and content check has a filter. Hooks receive a Subset\SEO\Templates\Subject: what the page is about. Build one yourself with Subject::current() for the main query or Subject::for_post( $post ).

Titles and descriptions

Titles and descriptions come from templates, set per page type on Subset → SEO → Titles & meta. A post’s own SEO title or description replaces the template’s.

<?php
// A %%price%% variable for templates. Return "" when it doesn't apply.
add_filter( 'subset_seo_template_variables', function ( array $resolvers ): array {
	$resolvers['price'] = fn ( \Subset\SEO\Templates\Subject $subject ): string =>
		$subject->post() ? (string) get_post_meta( $subject->post()->ID, 'price', true ) : '';
	return $resolvers;
} );

// The rendered title, as plain text. Return "" to leave WordPress's own.
add_filter( 'subset_seo_title', function ( string $title, $subject ): string {
	return $title;
}, 10, 2 );

subset_seo_description works the same way for the meta description. Social titles and descriptions fall back to both.

Head tags

<?php
// The canonical URL, or "" for none. og:url and the schema's page @id follow it.
add_filter( 'subset_seo_canonical', function ( string $url, $subject ): string {
	return $url;
}, 10, 2 );

// Robots directives, before core prints them through wp_robots.
add_filter( 'subset_seo_robots', function ( array $robots, $subject ): array {
	$robots['max-image-preview'] = 'large';
	return $robots;
}, 10, 2 );

subset_seo_indexable decides whether a page is indexed at all. A noindexed page prints no canonical and is left out of the sitemaps. Drafts, password-protected posts, search results and 404s stay noindexed whatever it returns.

subset_seo_open_graph and subset_seo_twitter filter the social tags, and subset_seo_social_image picks the share image. To print tags of your own inside Subset SEO’s head block, use the subset_seo_head action.

Schema

The graph is one JSON-LD @graph per page. Each node is a piece that points at the others by @id. Built-in pieces are website, organization, person, webpage, primaryimage, article, author and breadcrumb.

<?php
// Change one piece's data. Return an empty array to drop it.
add_filter( 'subset_seo_schema_piece_article', function ( array $data, $context ): array {
	$data['inLanguage'] = 'en-GB';
	return $data;
}, 10, 2 );

To describe something new, add a class implementing Subset\SEO\Schema\Piece (key(), needed( Context ) and data( Context )) through subset_seo_schema_pieces. subset_seo_schema_graph filters the whole graph before it prints.

Sitemaps

The index is /sitemap.xml, and each provider’s files are /{name}-sitemap.xml, /{name}-sitemap2.xml and so on. Files are cached and rebuilt when content changes.

<?php
// Leave a post, term or user out. Noindexed objects are left out already.
add_filter( 'subset_seo_sitemap_exclude', function ( bool $excluded, string $kind, $object ): bool {
	return $excluded || ( 'post' === $kind && get_post_meta( $object->ID, '_hide', true ) );
}, 10, 3 );

Add a provider of your own, a Subset\SEO\Sitemaps\Provider, through subset_seo_sitemap_types. subset_seo_sitemap_entry filters one URL and subset_seo_sitemap_per_file sets how many go in each file (1,000 by default).

Show the trail with the subset-seo/breadcrumbs block, the [subset_seo_breadcrumbs] shortcode or the template function:

<?php
// In a classic theme, declare support so the page's schema includes the BreadcrumbList.
add_theme_support( 'subset-seo-breadcrumbs' );

subset_seo_breadcrumbs( array( 'separator' => '/' ) );

subset_seo_breadcrumb_links filters the trail, from the home page to the current page. The trail, and the %%parent_title%% variable in titles and the preview, only use a parent that’s published and has no password.

Content checks

The editor’s checks run in the browser. Add one from a script that depends on subset-seo-editor:

subsetSEO.analysis.register({
  id: "acme_price",
  group: "seo", // or "readability"
  run: (paper) =>
    paper.text.includes("$")
      ? { status: "good", message: "The price is mentioned." }
      : { status: "note", message: "The text doesn't mention a price." },
});

A check returns good, note or problem, or null to skip. Its settings come from subset_seo_analysis_checks on the PHP side.

Meta keys

Values are stored under _subset_seo_ plus the field name: title, description, canonical, robots, og_title, og_description, og_image, tw_title, tw_description, tw_image, tw_card, focus_keyphrase, schema_type, breadcrumb_title and primary_term_{taxonomy}. Write them through the REST API or WP-CLI rather than directly, so values are cleaned the way the editor cleans them.

Authors’ Facebook, X and fediverse profiles are the unprefixed user meta facebook, twitter and mastodon, the keys other SEO plugins use. mastodon holds a handle (@name@example.social) or a profile URL.

_subset_seo_history keeps the last 10 values of a post’s title, description and robots. Every write to those keys, from anywhere, adds the value it replaced, with the user, the time and a source (editor, cli, import or a name an add-on gives). Read it with Subset\SEO\Meta\History::for( $post_id ) and put a value back with History::restore( $post_id, $field, $index ). An add-on that writes in bulk names itself with History::as( 'acme', fn () => PostMeta::update( … ) ).

Deleting the plugin keeps these values, so another SEO plugin can import them. Remove all Subset SEO data on Subset → SEO → Tools deletes them.

REST API and WP-CLI

The REST namespace is subset-seo/v1, with routes for an object’s SEO values (/meta/{type}/{id}), the search preview, a post’s field history (/history/{id}), imports and flushing the sitemap cache. The preview route’s social answer holds the Facebook and X cards the editor previews: for each, the title, description, image and warnings, plus card for X.

Every WP-CLI command lives under wp subset seo. WP-CLI commands lists each one with its options, defaults and examples, free and Pro.

Abilities for AI agents

On WordPress 6.9 and later, Subset SEO 0.13.0 registers three abilities. Each needs the right to edit the post, term or user it’s run on, the same check as the REST API. Abilities for AI agents explains how to run them.

AbilityInputWhat it does
subset-seo/get-metaobject_type (post, term or user), idReads the object’s SEO fields. Read-only.
subset-seo/update-metaobject_type, id, fieldsChanges only the fields it’s sent, through the same sanitising as the editor, and keeps the rest. The previous values go into the field history, so you can restore them.
subset-seo/check-postpost_idReturns the rendered title and description, robots, focus keyphrase, the editor’s last content analysis, and whether the post’s links point at published content. Read-only.

Who can change what

subset_seo_capability sets the capability that manages Subset SEO’s settings, tools, imports, robots.txt and AI keys. It’s manage_options by default, per site on multisite. A post’s, term’s or user’s own SEO fields still need edit_post, edit_term or edit_user.

Other SEO plugins

While Yoast SEO, Rank Math, All in One SEO or SEOPress is active, nothing SEO prints on the front end is registered, so its front-end filters don’t run. Site Health says why. subset_seo_conflicts filters that list of plugins, as slug => name. Add the filter from a plugin, since it runs on plugins_loaded.

Headless mode

For a site whose pages are built by another app, add this to wp-config.php:

define( 'SUBSET_SEO_HEADLESS', true );

Subset SEO then prints nothing on the front end: no title, meta tags, Open Graph, schema, sitemaps, robots.txt changes, llms.txt, verification codes, head cleanup or redirects. The settings screen, the editor fields, the REST API and WP-CLI keep working, so the app can read each object’s SEO values from subset-seo/v1/meta or the subset_seo field. The Advanced tab shows the mode as locked, and Site Health and the Subset Overview say it’s on.

WordPress’s own sitemaps (/wp-sitemap.xml) and robots.txt rules come back, as they would without the plugin. Turn the sitemaps off with wp_sitemaps_enabled if the app serves its own. The subset_seo_headless filter can turn the mode on from a plugin instead. Only true turns it on, and it runs on plugins_loaded.

Extending the plugin

An add-on attaches on subset_seo_loading, which fires before any component registers. subset_seo_admin_tabs adds a tab to Subset → SEO, printed on subset_seo_admin_tab_{slug}, and subset_seo_settings_defaults adds settings. subset_seo_tools prints on the Tools tab, and subset_seo_settings_after_form after a built-in tab’s form.