method_block_theme_button_before_label

 
 
 
 

apply_filters( 'method_block_theme_button_before_label', string $html )

Filters the default icon HTML displayed before the Theme Button label.


Description

Sets the HTML content (typically an SVG icon) that appears before the label text in every Theme Button instance. This filter serves as a global default — when method_block_theme_button_icons is registered, per‑button icon selections take priority over this value.


Parameters

$html (string) :
HTML markup to render before the label. Default: '' (empty string — no icon).


Source

PHP
'beforeLabel' => apply_filters( 'method_block_theme_button_before_label', '' ),

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


Usage

PHP
add_filter( 'method_block_theme_button_before_label', 'mytheme_button_before_icon' );

function mytheme_button_before_icon( $html ) {
    return '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><circle cx="8" cy="8" r="4"/></svg>';
}

Notes

  • The HTML is rendered inside <span class="method-button-icon method-button-icon-before"> on the frontend.
  • In the editor, it is rendered via dangerouslySetInnerHTML.
  • When method_block_theme_button_icons returns a non‑false value and the block has a beforeIcon attribute set, the per‑button icon selection overrides this global default.
  • If neither this filter nor method_block_theme_button_icons provides content, no before‑label icon element is rendered.
  • The data is passed to the editor via themeButtonData.beforeLabel.

Related


Changelog

VersionDescription
2.0.0-alpha4Introduced (a09be88).