Title: sanitize_textarea_field
Published: December 6, 2016
Last modified: May 20, 2026

---

# sanitize_textarea_field( string $str ): string

## In this article

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

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

Sanitizes a multiline string from user input or from the database.

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

The function is like [sanitize_text_field()](https://developer.wordpress.org/reference/functions/sanitize_text_field/),
but preserves new lines (\n) and other whitespace, which are legitimate input in
textarea elements.

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

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

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

 `$str`stringrequired

String to sanitize.

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

 string Sanitized string.

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

    ```php
    function sanitize_textarea_field( $str ) {
    	$filtered = _sanitize_text_fields( $str, true );

    	/**
    	 * Filters a sanitized textarea field string.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param string $filtered The sanitized string.
    	 * @param string $str      The string prior to being sanitized.
    	 */
    	return apply_filters( 'sanitize_textarea_field', $filtered, $str );
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/sanitize_textarea_field/?output_format=md#hooks)󠁿

 [apply_filters( ‘sanitize_textarea_field’, string $filtered, string $str )](https://developer.wordpress.org/reference/hooks/sanitize_textarea_field/)

Filters a sanitized textarea field string.

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

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

Internal helper function to sanitize a string from user input or from the database.

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

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [rest_sanitize_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_sanitize_value_from_schema/)`wp-includes/rest-api.php` |

Sanitize a value based on a schema.

  |

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

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

## User Contributed Notes

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