sanitize_title

The timeline below displays how wordpress function sanitize_title has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.6

/**
 * Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
 *
 * By default, converts accent characters to ASCII characters and further
 * limits the output to alphanumeric characters, underscore (_) and dash (-)
 * through the {@see 'sanitize_title'} filter.
 *
 * If `$title` is empty and `$fallback_title` is set, the latter will be used.
 *
 * @since 1.0.0
 *
 * @param string $title          The string to be sanitized.
 * @param string $fallback_title Optional. A title to use if $title is empty. Default empty.
 * @param string $context        Optional. The operation for which the string is sanitized.
 *                               When set to 'save', the string runs through remove_accents().
 *                               Default 'save'.
 * @return string The sanitized string.
 */
function sanitize_title($title, $fallback_title = '', $context = 'save')
{
    $raw_title = $title;
    if ('save' === $context) {
        $title = remove_accents($title);
    }
    /**
     * Filters a sanitized title string.
     *
     * @since 1.2.0
     *
     * @param string $title     Sanitized title.
     * @param string $raw_title The title prior to sanitization.
     * @param string $context   The context for which the title is being sanitized.
     */
    $title = apply_filters('sanitize_title', $title, $raw_title, $context);
    if ('' === $title || false === $title) {
        $title = $fallback_title;
    }
    return $title;
}

WordPress Version: 5.5

/**
 * Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
 *
 * By default, converts accent characters to ASCII characters and further
 * limits the output to alphanumeric characters, underscore (_) and dash (-)
 * through the {@see 'sanitize_title'} filter.
 *
 * If `$title` is empty and `$fallback_title` is set, the latter will be used.
 *
 * @since 1.0.0
 *
 * @param string $title          The string to be sanitized.
 * @param string $fallback_title Optional. A title to use if $title is empty. Default empty.
 * @param string $context        Optional. The operation for which the string is sanitized.
 *                               Default 'save'.
 * @return string The sanitized string.
 */
function sanitize_title($title, $fallback_title = '', $context = 'save')
{
    $raw_title = $title;
    if ('save' === $context) {
        $title = remove_accents($title);
    }
    /**
     * Filters a sanitized title string.
     *
     * @since 1.2.0
     *
     * @param string $title     Sanitized title.
     * @param string $raw_title The title prior to sanitization.
     * @param string $context   The context for which the title is being sanitized.
     */
    $title = apply_filters('sanitize_title', $title, $raw_title, $context);
    if ('' === $title || false === $title) {
        $title = $fallback_title;
    }
    return $title;
}

WordPress Version: 4.6

/**
 * Sanitizes a title, or returns a fallback title.
 *
 * Specifically, HTML and PHP tags are stripped. Further actions can be added
 * via the plugin API. If $title is empty and $fallback_title is set, the latter
 * will be used.
 *
 * @since 1.0.0
 *
 * @param string $title          The string to be sanitized.
 * @param string $fallback_title Optional. A title to use if $title is empty.
 * @param string $context        Optional. The operation for which the string is sanitized
 * @return string The sanitized string.
 */
function sanitize_title($title, $fallback_title = '', $context = 'save')
{
    $raw_title = $title;
    if ('save' == $context) {
        $title = remove_accents($title);
    }
    /**
     * Filters a sanitized title string.
     *
     * @since 1.2.0
     *
     * @param string $title     Sanitized title.
     * @param string $raw_title The title prior to sanitization.
     * @param string $context   The context for which the title is being sanitized.
     */
    $title = apply_filters('sanitize_title', $title, $raw_title, $context);
    if ('' === $title || false === $title) {
        $title = $fallback_title;
    }
    return $title;
}

WordPress Version: 4.3

/**
 * Sanitizes a title, or returns a fallback title.
 *
 * Specifically, HTML and PHP tags are stripped. Further actions can be added
 * via the plugin API. If $title is empty and $fallback_title is set, the latter
 * will be used.
 *
 * @since 1.0.0
 *
 * @param string $title          The string to be sanitized.
 * @param string $fallback_title Optional. A title to use if $title is empty.
 * @param string $context        Optional. The operation for which the string is sanitized
 * @return string The sanitized string.
 */
function sanitize_title($title, $fallback_title = '', $context = 'save')
{
    $raw_title = $title;
    if ('save' == $context) {
        $title = remove_accents($title);
    }
    /**
     * Filter a sanitized title string.
     *
     * @since 1.2.0
     *
     * @param string $title     Sanitized title.
     * @param string $raw_title The title prior to sanitization.
     * @param string $context   The context for which the title is being sanitized.
     */
    $title = apply_filters('sanitize_title', $title, $raw_title, $context);
    if ('' === $title || false === $title) {
        $title = $fallback_title;
    }
    return $title;
}

WordPress Version: 3.8

/**
 * Sanitizes a title, or returns a fallback title.
 *
 * Specifically, HTML and PHP tags are stripped. Further actions can be added
 * via the plugin API. If $title is empty and $fallback_title is set, the latter
 * will be used.
 *
 * @since 1.0.0
 *
 * @param string $title The string to be sanitized.
 * @param string $fallback_title Optional. A title to use if $title is empty.
 * @param string $context Optional. The operation for which the string is sanitized
 * @return string The sanitized string.
 */
function sanitize_title($title, $fallback_title = '', $context = 'save')
{
    $raw_title = $title;
    if ('save' == $context) {
        $title = remove_accents($title);
    }
    /**
     * Filter a sanitized title string.
     *
     * @since 1.2.0
     *
     * @param string $title     Sanitized title.
     * @param string $raw_title The title prior to sanitization.
     * @param string $context   The context for which the title is being sanitized.
     */
    $title = apply_filters('sanitize_title', $title, $raw_title, $context);
    if ('' === $title || false === $title) {
        $title = $fallback_title;
    }
    return $title;
}

WordPress Version: 3.7

/**
 * Sanitizes a title, or returns a fallback title.
 *
 * Specifically, HTML and PHP tags are stripped. Further actions can be added
 * via the plugin API. If $title is empty and $fallback_title is set, the latter
 * will be used.
 *
 * @since 1.0.0
 *
 * @param string $title The string to be sanitized.
 * @param string $fallback_title Optional. A title to use if $title is empty.
 * @param string $context Optional. The operation for which the string is sanitized
 * @return string The sanitized string.
 */
function sanitize_title($title, $fallback_title = '', $context = 'save')
{
    $raw_title = $title;
    if ('save' == $context) {
        $title = remove_accents($title);
    }
    $title = apply_filters('sanitize_title', $title, $raw_title, $context);
    if ('' === $title || false === $title) {
        $title = $fallback_title;
    }
    return $title;
}