Skip to main content

Add a custom icon to the per-tier badge picker

Free Beginner Since v1.0.0

BadgeIconRegistry::get_icons() runs benecaster_badge_icons to merge add-on icons into the built-in set. Each entry is [ 'slug' => string, 'label' => string, 'svg' => string ]; the SVG must use fill="currentColor" so the badge chip’s accent color is honored. Entries missing any of the three keys are silently dropped. Because the slug is persisted to benecaster_badge_definitions.icon_slug, removing a filter-registered icon later does not break existing badges — the controller falls back to rendering label and color without a glyph.

Code

<?php
add_filter( 'benecaster_badge_icons', function ( array $icons ): array {
    $icons['rocket'] = [
        'slug'  => 'rocket',
        'label' => __( 'Rocket', 'my-addon' ),
        'svg'   => '<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M..."/></svg>',
    ];
    return $icons;
} );

View on GitHub →

Hooks Used