获取帖子标题。
原型
gutenberg_draft_or_post_title( int|WP_Post $post )
描述
获取帖子标题,如果为空,则返回默认字符串。
参数
$post
(int|WP_Post)
(Optional)
发布ID或WP_Post对象。默认为全球$ post。
返回值
(string)
帖子标题如果设置; “(无标题)”如果没有设定标题。
源文件
路径:wp-includes/blocks/latest-comments.php
<?php
...
function gutenberg_draft_or_post_title( $post = 0 ) {
$title = get_the_title( $post );
if ( empty( $title ) ) {
$title = __( '(no title)' );
}
return esc_html( $title );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/gutenberg_draft_or_post_title/