method_theme_icons

 
 
 
 

apply_filters( 'method_theme_icons', array $icons )

Filters the shared set of SVG icons Method’s blocks offer — the swiper arrows, theme button icons and the modal close button — and registers with WordPress’s icon library.


Description

method_get_theme_icons() builds the icon set by passing an empty array through method_block_theme_button_icons (the older Theme Button hook, kept for compatibility) and then this filter, so a child theme that already supplies button icons keeps working and new icons go here. Each icon is keyed by slug and carries a label and the inline svg; an optional omit keeps it out of WordPress’s icon library while leaving it available to Method’s own controls. The set is localised for the editor as methodGlobalData.icons and registered on init as the Method icon collection by method_register_theme_icons(). The whole system is on the Theme Icons page.


Parameters

$icons (array) :
Slug ⇒ array( 'label' => string, 'svg' => string, 'omit' => bool ). Arrives holding whatever method_block_theme_button_icons returned; empty by default.


Source

File: lib/blocks.php, function method_get_theme_icons()

PHP
$icons = apply_filters( 'method_block_theme_button_icons', $icons );
$icons = apply_filters( 'method_theme_icons', $icons );
return ( 0 < count( $icons ) ? $icons : false );

Usage

child-theme/functions.php
add_filter( 'method_theme_icons', function ( array $icons ) {
    $icons['arrow-right'] = array(
        'label' => 'Arrow right',
        'svg'   => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M1 8h12M9 4l4 4-4 4"/></svg>',
    );
    return $icons;
} );

Notes

  • Read on every page render that prints an icon and once per editor load, so keep the SVG strings in the callback rather than reading files each time.
  • Icons are printed as is ($icons[ $slug ]['svg']), so the markup must be trusted; use currentColor so the blocks’ color controls apply, and a viewBox so the icon scales.
  • Slugs become block attribute values (prevIcon, closeIcon, …): renaming one orphans the blocks that chose it, which then fall back to their defaults.

Related


Changelog

VersionDescription
2.0.0-beta18Introduced, with method_get_theme_icons() and the Method icon collection (3064cd9).