sanitize_title
Sanitizes a title, or returns a fallback title.
Description
(string) sanitize_title( (string) $title, (string) $fallback_title = '', (string) $context = 'save' );
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.
Returns (string)
The sanitized string.
Parameters (3)
- 0. $title (string)
- The string to be sanitized.
- 1. $fallback_title — Optional. (string) =>
''
- A title to use if
$title
is empty. - 2. $context — Optional. (string) =>
'save'
- The operation for which the string is sanitized
Usage
if ( !function_exists( 'sanitize_title' ) ) { require_once ABSPATH . WPINC . '/formatting.php'; } // The string to be sanitized. $title = ''; // Optional. A title to use if $title is empty. $fallback_title = ''; // Optional. The operation for which the string is sanitized $context = 'save'; // NOTICE! Understand what this does before running. $result = sanitize_title($title, $fallback_title, $context);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/formatting.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;
- }