Developer guidesRecipes for agencies

Recipes for agencies

Short, tested answers to the tasks that come up on every client project: icon sets per client, icons from hooks and template parts, your own collections, WP-CLI in scripts, one configuration for every site and abilities for AI agents.

Each recipe is code you can copy, run on a real site and check. The outputs below come from WordPress 7.1 with Easy SVG 5.0 and Easy SVG Pro 1.0. Only public hooks, functions and commands are used, so the recipes keep working after updates.

Pro switches are under Easy SVG → Settings → Features. Most recipes need Collections; the WP-CLI ones need WP-CLI too.

Ship a client's icons as a set

Three ways to bring one client's icons to their site. All three give the same result: a collection, an address collection/slug per icon, and the icons in the Icon block, in every icon picker and in easy_svg_icon().

WayTake it whenWhere the icons live
Theme folderThe icons belong to the client's themewp-content/themes/<theme>/assets/icons/
Drop-in folderYou manage the site by hand or by WP-CLIwp-content/easy-svg-icons/<slug>/
PluginThe same icons go to several sites, or into Gitwp-content/plugins/<name>/icons/<slug>/

Put the SVGs and a manifest.json into the theme's assets/icons/. Pro reads the folder by itself, child theme over parent. The manifest names the collection:

{
  "version": 1,
  "slug": "acme-theme",
  "label": "ACME theme icons",
  "license": "GPL-2.0-or-later",
  "author": "ACME agency",
  "source": "https://example.com/acme-theme",
  "icons": [
    { "file": "circle.svg", "name": "circle", "label": "Circle", "keywords": ["round", "dot"] }
  ]
}
wp easy-svg icons list --fields=collection,count,origin
collection  count  origin
acme-theme  3      theme twentytwentyfive

Without a manifest the collection is called theme. Template: templates/theme.

Give every folder a collection slug nobody else uses, for example the client's name. Two folders with the same slug both load, but one of them is renamed with a suffix, and pages that stored the old address then show the other folder's icons. Check with wp easy-svg icons list after you add a folder.

Your theme calls a hook, a small plugin answers it. The icon stays out of the template, and a child theme or a client plugin can change it.

<?php
/**
 * Plugin Name: ACME header icon
 */

// In header.php or a template part, call: do_action( 'acme_header_tools' );
add_action(
	'acme_header_tools',
	static function () {
		if ( ! function_exists( 'easy_svg_icon' ) ) {
			return;
		}
		printf(
			'<a class="acme-phone" href="tel:+493012345678">%s<span>%s</span></a>',
			easy_svg_icon( 'acme-theme/circle', array( 'class' => 'acme-phone__icon' ) ), // phpcs:ignore WordPress.Security.EscapeOutput
			esc_html__( 'Call us', 'acme' )
		);
	}
);

Output of do_action( 'acme_header_tools' ):

<a class="acme-phone" href="tel:+493012345678"><svg class="easy-svg-icon acme-phone__icon" fill="currentColor" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/>
</svg><span>Call us</span></a>
Do not write <?php ... ?> inside a // comment. PHP ends its code at ?>, even in a comment, and prints the rest of the file as text on every page. php -l does not catch it.

In a block theme

A template part takes the core Icon block directly:

<!-- wp:icon {"icon":"acme-theme/circle"} /-->

To put an icon into a Button block, give the button the extra CSS class acme-icon-<slug> in the editor, and filter its output:

<?php
/**
 * Plugin Name: ACME button icons
 */

add_filter(
	'render_block_core/button',
	static function ( $html, $block ) {
		$class = (string) ( $block['attrs']['className'] ?? '' );
		if ( ! function_exists( 'easy_svg_icon' ) || 1 !== preg_match( '/(?:^|\s)acme-icon-([a-z0-9-]+)/', $class, $m ) ) {
			return $html;
		}
		$icon = easy_svg_icon( 'acme-theme/' . $m[1], array( 'class' => 'acme-button__icon' ) );
		if ( '' === $icon ) {
			return $html;
		}
		return (string) preg_replace_callback(
			'/<a\b[^>]*>/',
			static function ( $open ) use ( $icon ) {
				return $open[0] . $icon;
			},
			$html,
			1
		);
	},
	10,
	2
);

A button with the class acme-icon-circle and the text "Call us" renders as:

<div class="wp-block-button acme-icon-circle"><a class="wp-block-button__link wp-element-button"><svg class="easy-svg-icon acme-button__icon" fill="currentColor" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/>
</svg>Call us</a></div>

preg_replace_callback() and not preg_replace(): an icon label with $1 in it would otherwise be read as a back reference. More on themes: Render icons in themes.

Register a collection of your own

Two public ways. Both read manifest.json, sanitize every file and cache the scan for 60 seconds.

<?php
/**
 * Plugin Name: ACME client icons
 */

// The function: the slug you pass names the collection, whatever the manifest says.
// On init at 10: Pro reads its own folders at 9 and hands the icons to the Icon block at 11.
add_action(
	'init',
	static function () {
		if ( ! function_exists( 'easy_svg_register_icon_collection' ) ) {
			return;
		}
		easy_svg_register_icon_collection( 'client-a', 'Client A', WP_CONTENT_DIR . '/client-icons/client-a' );
	}
);

// The filter: Pro reads the folder like a drop-in. Its manifest slug names the collection.
add_filter(
	'easy_svg_pro_source_dirs',
	static function ( $dirs ) {
		$dirs   = is_array( $dirs ) ? $dirs : array();
		$dirs[] = WP_CONTENT_DIR . '/client-icons/client-b';
		return $dirs;
	}
);
wp easy-svg icons list --fields=collection,count,origin
collection  count  origin
client-a    3      folder client-a
client-b    3      folder client-b
easy_svg_register_icon_collection()easy_svg_pro_source_dirs
Name of the collectionThe slug you passThe manifest's slug, else the folder name
Also takes inline markupYes, array( 'close' => '<svg …>' )No
Where to call itinit, priority 10Any time before init 9

The filter callback takes its argument untyped and casts it: another plugin may have broken the list before yours. More: easy_svg_register_icon_collection(), easy_svg_pro_source_dirs, snippets register-collection.php and source-folders.php.

Import icons with WP-CLI and read the result in scripts

Every list command takes --format=json, csv, yaml or count. Notes for people, such as "run wp easy-svg icons problems to see why", appear only in the table format, so the JSON stays clean.

wp easy-svg icons import ./acme-icons --collection=acme --label="ACME Icons"
wp easy-svg icons list --format=json
[{"collection":"acme","label":"ACME Icons","count":3,"origin":"dropin acme","problems":0},{"collection":"easy-svg","label":"Easy SVG","count":1,"origin":"library","problems":0}]

For a single number or a list of names: --format=count prints 2, --format=ids prints acme easy-svg.

Fail a deploy when any collection lost a file, with jq:

broken=$(wp easy-svg icons list --format=json | jq -r '.[] | select(.problems > 0) | .collection')
if [ -n "$broken" ]; then
  echo "Icons missing in: $broken"
  wp easy-svg icons problems
  exit 1
fi

Check a folder in CI before it ships. --strict exits with 1 when any file would be skipped:

wp easy-svg icons validate ./icons --strict
wp easy-svg icons validate ./icons --format=json

Two rows of the answer for a folder with one broken file:

[{"file":"./icons/big.svg","slug":"big","status":"ok","reason":""},{"file":"./icons/not-svg.svg","slug":"not-svg","status":"skipped","reason":"not-svg"}]

ok means the file loads after the sanitizer cleaned it, not that it was clean before.

The checker tools/check-pack.php from the dev setup needs no WordPress and is stricter: it refuses scripts, external references and missing license fields that the sanitizer would only clean. More: Automate with WP-CLI.

One configuration for every site

Ship wp-content/easy-svg-pro.json with your code. A switch named there is fixed: the Features screen shows it locked, and deleting the file gives each site its own choice back.

{
  "features": {
    "sets": true,
    "cli": true,
    "icon_field_blocks": true
  },
  "environments": {
    "production": { "features": { "abilities": false } }
  }
}

environments follows wp_get_environment_type(): local, development, staging or production. Check what a site reads:

wp easy-svg config
Configuration file: /var/www/html/wp-content/easy-svg-pro.json
key                        value  stored
features.sets              true   true
features.cli               true   true
features.icon_field_blocks true   true

value counts, stored is what the site had saved itself. Keep the file somewhere else with define( 'EASY_SVG_PRO_CONFIG', '/path/to/easy-svg-pro.json' ); in wp-config.php. In code, the filter easy_svg_pro_config( array $config, int $site_id ) has the last word.

SwitchKey
Collectionssets
WP-CLIcli
AI agents (MCP)abilities
PHP-only blocksicon_field_blocks
ACF, Secure Custom Fields, Lazy Blocksicon_field_acf, icon_field_scf, icon_field_lazyblocks
Elementor, Meta Box, WPBakeryelementor, metabox, wpbakery
Templatestemplates (Share links follow it)

More: Central configuration, EASY_SVG_PRO_CONFIG, easy_svg_pro_config.

Let an AI agent work with your icons

Pro registers 42 abilities in the category easy-svg-pro (WordPress Abilities API). An MCP server for WordPress offers them to AI clients. The switch AI agents (MCP) is on by default; every ability needs manage_options.

From PHP, as an administrator:

wp eval 'echo wp_json_encode( wp_get_ability( "easy-svg-pro/list-icons" )->execute( array( "search" => "circle", "per_page" => 2 ) ), JSON_PRETTY_PRINT );' --user=admin
{
    "items": [
        { "slug": "circle", "label": "Circle", "collection": "acme-theme", "source": "collection" },
        { "slug": "circle", "label": "Circle", "collection": "acme", "source": "collection" }
    ],
    "total": 5,
    "page": 1,
    "per_page": 2,
    "has_more": true,
    "truncated": false
}

Without --user the ability answers with a WP_Error: no user, no rights.

Over REST, with an application password:

curl -u "admin:APPLICATION PASSWORD" \
  "https://example.com/wp-json/wp-abilities/v1/abilities/easy-svg-pro/list-icons/run?input%5Bsearch%5D=heart"
{"items":[{"slug":"heart","label":"Heart","collection":"easy-svg","source":"library"}],"total":1,"page":1,"per_page":100,"has_more":false,"truncated":false}

Reading abilities take GET, the others POST or DELETE. The wrong method answers 405. All 42 with their input, and how to connect a client: Abilities for AI agents.

Next