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

---

# WP_REST_Controller::sanitize_slug( string $slug ): string

## In this article

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

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

Sanitizes the slug value.

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

{@internal We can’t use [sanitize_title()](https://developer.wordpress.org/reference/functions/sanitize_title/)
directly, as the second parameter is the fallback title, which would end up being
set to the request object.}

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

 `$slug`stringrequired

Slug value passed in request.

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

 string Sanitized value for the slug.

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

    ```php
    public function sanitize_slug( $slug ) {
    	return sanitize_title( $slug );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php#L678)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php#L678-L680)

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

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

Sanitizes a string into a slug, which can be used in URLs or HTML attributes.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_controller/sanitize_slug/?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%2Fclasses%2Fwp_rest_controller%2Fsanitize_slug%2F)
before being able to contribute a note or feedback.