wppaste
WordPress

sanitize_title( string $title, string $fallback_title = '', string $context = 'save' ): string

Since
1.0.0
Source
wp-includes/formatting.php:2227
Sanitizes a string into a slug, which can be used in URLs or HTML attributes.

Description

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.

Parameters

$titlestring
The string to be sanitized.
$fallback_titlestringoptional
A title to use if $title is empty. Default empty.Default: ''
$contextstringoptional
The operation for which the string is sanitized. When set to 'save', the string runs through remove_accents(). Default 'save'.Default: 'save'

Return

string
The sanitized string.

Hooks fired · 1

One hook fires while sanitize_title() runs, in this order:

  1. apply_filters( sanitize_title )filterline 2243 (+16 into the body)

    Filters a sanitized title string.

Uses · 2

Used by · 50

Show all 50

Source

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

History

Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.