Title: WP_Icons_Registry::sanitize_icon_content
Published: May 20, 2026

---

# WP_Icons_Registry::sanitize_icon_content( string $icon_content ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#related)

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

Sanitizes the icon SVG content.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#description)󠁿

Logic borrowed from twentytwenty.

### 󠀁[See also](https://developer.wordpress.org/reference/classes/wp_icons_registry/sanitize_icon_content/?output_format=md#see-also)󠁿

 * twentytwenty_get_theme_svg

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

 `$icon_content`stringrequired

The icon SVG content to sanitize.

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

 string The sanitized icon SVG content.

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

    ```php
    protected function sanitize_icon_content( $icon_content ) {
    	$allowed_tags = array(
    		'svg'     => array(
    			'class'       => true,
    			'xmlns'       => true,
    			'width'       => true,
    			'height'      => true,
    			'viewbox'     => true,
    			'aria-hidden' => true,
    			'role'        => true,
    			'focusable'   => true,
    		),
    		'path'    => array(
    			'fill'      => true,
    			'fill-rule' => true,
    			'd'         => true,
    			'transform' => true,
    		),
    		'polygon' => array(
    			'fill'      => true,
    			'fill-rule' => true,
    			'points'    => true,
    			'transform' => true,
    			'focusable' => true,
    		),
    	);
    	return wp_kses( $icon_content, $allowed_tags );
    }
    ```

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

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

| Uses | Description | 
| [wp_kses()](https://developer.wordpress.org/reference/functions/wp_kses/)`wp-includes/kses.php` |

Filters text content and strips out disallowed HTML.

  |

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

Registers an icon.

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

Retrieves the content of a registered icon.

  |

## User Contributed Notes

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