method_block_theme_button_icons

 
 
 
 

apply_filters( 'method_block_theme_button_icons', mixed $icons )

Filters the icon options available in the Theme Button block.


Description

Registers selectable icon options that appear in “Icon (Before Label)” and “Icon (After Label)” dropdowns in the Theme Button block’s Inspector panel. When icons are registered, editors can choose an icon to display alongside the button label.

Since beta18 this filter is applied inside method_get_theme_icons() — the array it returns is the starting value for the method_theme_icons filter, so icons registered here join the shared theme icon set used by the Theme Button, the Swiper arrows and the Modal close button alike, and are localised for the editor as methodGlobalData.icons. New code should use method_theme_icons; this hook remains so existing child themes keep working. Return an array: the result is counted, so returning false is no longer safe (count(false) is a TypeError on PHP 8) — return an empty array to register nothing.

Before beta18, when this filter returned false (the default), the icon selectors were hidden and the block falls back to method_block_theme_button_before_label / method_block_theme_button_after_label for default icon markup.


Parameters

$icons (array) :
An associative array where keys are icon identifiers and values are arrays containing a label and svg string (an optional omit keeps an icon out of WordPress’s icon library). Arrives empty. Return an array; an empty one registers nothing.

PHP
array(
    'arrow-right' => array(
        'label' => 'Arrow Right',
        'svg'   => '<svg xmlns="http://www.w3.org/2000/svg" ...>...</svg>',
    ),
    'arrow-down' => array(
        'label' => 'Arrow Down',
        'svg'   => '<svg xmlns="http://www.w3.org/2000/svg" ...>...</svg>',
    ),
    'external' => array(
        'label' => 'External Link',
        'svg'   => '<svg xmlns="http://www.w3.org/2000/svg" ...>...</svg>',
    ),
)

Source

PHP
'buttonIcons' => apply_filters( 'method_block_theme_button_icons', $defaults ),

File: lib/blocks.php, function method_get_theme_icons() (before beta18: lib/blocks/method-buttons/method-buttons.php, method_theme_button_enqueue_block_assets())


Usage

PHP
add_filter( 'method_block_theme_button_icons', 'mytheme_button_icons' );

function mytheme_button_icons( $icons ) {
    return array(
        '' => array(
            'label' => 'None',
            'svg'   => '',
        ),
        'chevron-right' => array(
            'label' => 'Chevron Right',
            'svg'   => '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708"/></svg>',
        ),
        'arrow-right' => array(
            'label' => 'Arrow Right',
            'svg'   => '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8"/></svg>',
        ),
    );
}

Notes

  • The selected icon keys are stored in the block’s beforeIcon and afterIcon attributes.
  • On the frontend, the icon SVG is rendered inside <span class="method-button-icon method-button-icon-before"> or <span class="method-button-icon method-button-icon-after">.
  • Include an empty‑string key with an empty SVG to provide a “None” option.
  • When icons are registered via this filter, they take priority over the method_block_theme_button_before_label and method_block_theme_button_after_label fallback filters.
  • Icons should use fill="currentColor" to inherit button text color.
  • The data is passed to the editor via themeButtonData.buttonIcons.

Related

  • method_block_theme_button_before_label — Default before‑label icon (fallback)
  • method_block_theme_button_after_label — Default after‑label icon (fallback)
  • method_block_theme_button_styles — Button style presets
  • Buttons block

Changelog

VersionDescription
2.0.0-beta4Introduced (9ef2798).
2.0.0-beta18Applied inside method_get_theme_icons() as the seed of the shared theme icon set, ahead of the new method_theme_icons filter; the Theme Button-specific buttonIcons localisation was removed (3064cd9).