get_the_title

Retrieve post title.

Description

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

If the post is protected and the visitor is not an admin, then Protected will be displayed before the post title. If the post is private, then "Private" will be located before the post title.

Returns (string)

Parameters (1)

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

Usage

  1. if ( !function_exists( 'get_the_title' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-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 = get_the_title($post); 
  9.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function get_the_title( $post = 0 ) { 
  2. $post = get_post( $post ); 
  3.  
  4. $title = isset( $post->post_title ) ? $post->post_title : ''; 
  5. $id = isset( $post->ID ) ? $post->ID : 0; 
  6.  
  7. if ( ! is_admin() ) { 
  8. if ( ! empty( $post->post_password ) ) { 
  9.  
  10. /** 
  11. * Filters the text prepended to the post title for protected posts. 
  12. * The filter is only applied on the front end. 
  13. * @since 2.8.0 
  14. * @param string $prepend Text displayed before the post title. 
  15. * Default 'Protected: %s'. 
  16. * @param WP_Post $post Current post object. 
  17. */ 
  18. $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post ); 
  19. $title = sprintf( $protected_title_format, $title ); 
  20. } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) { 
  21.  
  22. /** 
  23. * Filters the text prepended to the post title of private posts. 
  24. * The filter is only applied on the front end. 
  25. * @since 2.8.0 
  26. * @param string $prepend Text displayed before the post title. 
  27. * Default 'Private: %s'. 
  28. * @param WP_Post $post Current post object. 
  29. */ 
  30. $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post ); 
  31. $title = sprintf( $private_title_format, $title ); 
  32.  
  33. /** 
  34. * Filters the post title. 
  35. * @since 0.71 
  36. * @param string $title The post title. 
  37. * @param int $id The post ID. 
  38. */ 
  39. return apply_filters( 'the_title', $title, $id );