_draft_or_post_title

Get the post title.

Description

(string) _draft_or_post_title( (int) $post = 0 ); 

The post title is fetched and if it is blank then a default string is returned.

Returns (string)

The post title if set.

Parameters (1)

0. $post — Optional. (int)
Post ID or WP_Post object. Default is global $post.

Usage

  1. if ( !function_exists( '_draft_or_post_title' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global $post. 
  5. $post = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _draft_or_post_title($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function _draft_or_post_title( $post = 0 ) { 
  2. $title = get_the_title( $post ); 
  3. if ( empty( $title ) ) 
  4. $title = __( '(no title)' ); 
  5. return esc_html( $title );