WordPress at a glance

sanitize_title() WP 1.0

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.

Is the basis for: wp_parse_slug_list()
✈ 1 time = 0.000197s = fast | 50000 times = 6.03s = fast PHP 7.0.2, WP 4.4.2
Hooks from 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
Default: 'save'

Code of sanitize_title: wp-includes/formatting.php VER 4.9.8

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

Related Functions

From tag: sanitize_

More from category: Sanitizing, Escaping

No comments
    Hello, !     Log In . Register