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.

When this filter returns false (the default), the icon selectors are 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|false) :
An associative array where keys are icon identifiers and values are arrays containing a label and svg string. Pass false to hide the icon selectors.

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/method-buttons/method-buttons.php, function 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.0Introduced.