single_post_title

函式
single_post_title ( $prefix = '', $display = true )
引數
  • (string) $prefix Optional. What to display before the title.
    Required:
    Default: (empty)
  • (bool) $display Optional. Whether to display or retrieve title. Default true.
    Required:
    Default: true
返回值
  • (string|void) Title when retrieving.
定義位置
相關方法
single_month_titlesingle_cat_titlesingle_tag_titlesingle_term_titleget_post_time
引入
0.71
棄用
-

single_post_title:這個WordPress函式是用來顯示一個單一的文章的標題。它接受兩個引數–$prefix和$display。$prefix引數是可選的,允許你為標題新增字首,而$display引數也是可選的,允許你控制標題是否顯示在螢幕上或作為一個字串返回。

顯示或檢索文章的頁面標題。

這是對single.php模板檔案的優化,用於顯示文章的標題。

它不支援在標題後放置分隔符,但通過將字首引數留空,你可以手動設定標題分隔符。字首不會自動在字首之間放置空格,所以如果應該有空格,引數值就需要在最後有。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function single_post_title( $prefix = '', $display = true ) {
$_post = get_queried_object();
if ( ! isset( $_post->post_title ) ) {
return;
}
/**
* Filters the page title for a single post.
*
* @since 0.71
*
* @param string $_post_title The single post page title.
* @param WP_Post $_post The current post.
*/
$title = apply_filters( 'single_post_title', $_post->post_title, $_post );
if ( $display ) {
echo $prefix . $title;
} else {
return $prefix . $title;
}
}
function single_post_title( $prefix = '', $display = true ) { $_post = get_queried_object(); if ( ! isset( $_post->post_title ) ) { return; } /** * Filters the page title for a single post. * * @since 0.71 * * @param string $_post_title The single post page title. * @param WP_Post $_post The current post. */ $title = apply_filters( 'single_post_title', $_post->post_title, $_post ); if ( $display ) { echo $prefix . $title; } else { return $prefix . $title; } }
function single_post_title( $prefix = '', $display = true ) {
	$_post = get_queried_object();

	if ( ! isset( $_post->post_title ) ) {
		return;
	}

	/**
	 * Filters the page title for a single post.
	 *
	 * @since 0.71
	 *
	 * @param string  $_post_title The single post page title.
	 * @param WP_Post $_post       The current post.
	 */
	$title = apply_filters( 'single_post_title', $_post->post_title, $_post );
	if ( $display ) {
		echo $prefix . $title;
	} else {
		return $prefix . $title;
	}
}

常見問題

FAQs
檢視更多 >