WordPress at Your Fingertips

sanitize_title() WP 1.0

Sanitizes a title, or returns a fallback title.

By default, converts accent characters to ASCII characters and further limits the output to alphanumeric characters, underscore (_) and dash (-) through the sanitize_title filter.

If $title is empty and $fallback_title is set, the latter will be used.

1 time — 0.000197 sec (fast) | 50000 times — 6.03 sec (fast) | PHP 7.0.2, WP 4.4.2
Hooks from the function
Return

String. The sanitized string.

Usage

sanitize_title( $title, $fallback_title, $context );
$title(string) (required)
The string to be sanitized.
$fallback_title(string)
A title to use if $title is empty.
Default: ''
$context(string)
The operation for which the string is sanitized. When set to 'save', the string runs through remove_accents().
Default: 'save'

Changelog

Since 1.0.0 Introduced.

Code of sanitize_title() WP 5.8.1

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;
}

sanitize_

Sanitizing, Escaping

No comments
    Log In