Title: wp_sanitize_script_attributes
Published: March 9, 2021
Last modified: August 20, 2026

---

# wp_sanitize_script_attributes( $attributes ): string

## In this article

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

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

This function has been deprecated since 7.0.0. Use [wp_get_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_script_tag/)
instead.

Sanitizes an attributes array into an attributes string to be placed inside a  tag.

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

This function is deprecated, use [wp_get_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_script_tag/)
or [wp_get_inline_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_inline_script_tag/)
instead.

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

 * [wp_get_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_script_tag/)
 * [wp_get_inline_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_inline_script_tag/)

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

`string|bool`> $attributes Key-value pairs representing `<script>` tag attributes.

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

 string String made of sanitized `<script>` tag attributes.

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

    ```php
    function wp_sanitize_script_attributes( $attributes ) {
    	_deprecated_function( __FUNCTION__, '7.0.0', 'wp_get_script_tag() or wp_get_inline_script_tag()' );

    	$attributes_string = '';
    	foreach ( $attributes as $attribute_name => $attribute_value ) {
    		if ( is_bool( $attribute_value ) ) {
    			if ( $attribute_value ) {
    				$attributes_string .= ' ' . esc_attr( $attribute_name );
    			}
    		} else {
    			$attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
    		}
    	}
    	return $attributes_string;
    }
    ```

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

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

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

Escaping for HTML attributes.

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

Marks a function as deprecated and inform when it has been used.

  |

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

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Deprecated. Use [wp_get_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_script_tag/) or [wp_get_inline_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_inline_script_tag/) . | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. |

## User Contributed Notes

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