Title: wp_get_icon
Published: August 20, 2026

---

# wp_get_icon( string $name, array $args = array() ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#wp--skip-link--target)

Returns the SVG markup for a registered icon.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#parameters)󠁿

 `$name`stringrequired

The namespaced icon name (e.g. `'core/plus'`, `'core/arrow-down'`, `'my-plugin/custom-
icon'`).

`$args`arrayoptional

Arguments for the icon.

 * `size` int|null
 * Width and height in pixels. Pass null to leave the SVG’s intrinsic dimensions
   untouched. Default 24.
 * `class` string
 * Additional CSS class names. Multiple classes may be provided as a space-separated
   string.
 * `label` string
 * Accessible label. If provided, the SVG gets role="img" and aria-label. If omitted,
   the SVG gets aria-hidden="true" and focusable="false".

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#return)󠁿

 string SVG markup for the icon, or empty string if not found.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#source)󠁿

    ```php
    function wp_get_icon( $name, $args = array() ) {
    	$icon = WP_Icons_Registry::get_instance()->get_registered_icon( $name );
    	if ( is_null( $icon ) ) {
    		return '';
    	}

    	$svg = $icon['content'];
    	if ( empty( $svg ) ) {
    		return '';
    	}

    	$args = wp_parse_args(
    		$args,
    		array(
    			'size'  => 24,
    			'class' => '',
    			'label' => '',
    		)
    	);

    	$processor = new WP_HTML_Tag_Processor( $svg );
    	if ( ! $processor->next_tag( 'svg' ) ) {
    		return '';
    	}

    	if ( is_numeric( $args['size'] ) ) {
    		$size = absint( $args['size'] );
    		$processor->set_attribute( 'width', (string) $size );
    		$processor->set_attribute( 'height', (string) $size );
    	}

    	if ( ! empty( $args['class'] ) ) {
    		foreach ( preg_split( '/\s+/', $args['class'], -1, PREG_SPLIT_NO_EMPTY ) as $class_name ) {
    			$processor->add_class( $class_name );
    		}
    	}

    	if ( ! empty( $args['label'] ) ) {
    		$processor->set_attribute( 'role', 'img' );
    		$processor->set_attribute( 'aria-label', $args['label'] );
    		$processor->remove_attribute( 'aria-hidden' );
    		$processor->remove_attribute( 'focusable' );
    	} else {
    		$processor->set_attribute( 'aria-hidden', 'true' );
    		$processor->set_attribute( 'focusable', 'false' );
    		$processor->remove_attribute( 'role' );
    		$processor->remove_attribute( 'aria-label' );
    	}

    	return $processor->get_updated_html();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/icons.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/icons.php#L166)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/icons.php#L166-L216)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Icons_Registry::get_instance()](https://developer.wordpress.org/reference/classes/wp_icons_registry/get_instance/)`wp-includes/class-wp-icons-registry.php` |

Utility method to retrieve the main instance of the class.

  | 
| [WP_HTML_Tag_Processor::__construct()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/__construct/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Constructor.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [absint()](https://developer.wordpress.org/reference/functions/absint/)`wp-includes/load.php` |

Converts a value to non-negative integer.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_icon/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_icon%2F)
before being able to contribute a note or feedback.