sanitize_title

函式
sanitize_title ( $title, $fallback_title = '', $context = 'save' )
引數
  • (string) $title The string to be sanitized.
    Required:
  • (string) $fallback_title Optional. A title to use if $title is empty. Default empty.
    Required:
    Default: (empty)
  • (string) $context Optional. The operation for which the string is sanitized. When set to 'save', the string runs through remove_accents(). Default 'save'.
    Required:
    Default: 'save'
返回值
  • (string) The sanitized string.
定義位置
相關方法
sanitize_termsanitize_urlsanitize_keysanitize_optionsanitize_file_name
引入
1.0.0
棄用
-

sanitize_title: 這是一個WordPress的函式,可以對文章或術語的標題進行淨化處理。它用於刪除任何HTML標籤和特殊字元,並建立一個使用者友好的標題: 這個函式有一個引數,就是要淨化的標題。

將一個字串淨化成一個lug,可以在URL或HTML屬性中使用。

預設情況下,將重音字元轉換為ASCII字元,並進一步限制輸出為字母數字字元、下劃線(_)和破折號(-)。
通過{@see ‘sanitize_title’}過濾器。

如果`$title’為空而`$fallback_title’被設定,將使用後者。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >