wppaste
WordPress

get_the_title( int|WP_Post $post = 0 ): string

Since
0.71
Source
wp-includes/post-template.php:118
Retrieves the post title.

Description

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

Parameters

$postint|WP_Postoptional
Post ID or WP_Post object. Default is global $post.Default: 0

Return

string

Hooks fired · 3

3 hooks fire while get_the_title() runs, in this order:

  1. apply_filters( protected_title_format )filterline 141 (+23 into the body)

    Filters the text prepended to the post title for protected posts.

  2. apply_filters( private_title_format )filterline 160 (+42 into the body)

    Filters the text prepended to the post title of private posts.

  3. apply_filters( the_title )filterline 174 (+56 into the body)

    Filters the post title.

Uses · 4

  • get_post()Retrieves post data given a post ID or post object.
  • is_admin()Determines whether the current request is for an administrative interface page.
  • __()Retrieves the translation of $text.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Used by · 47

Show all 47

Source

function get_the_title( $post = 0 ) {	$post = get_post( $post ); 	$post_title = $post->post_title ?? '';	$post_id    = $post->ID ?? 0; 	if ( ! is_admin() ) {		if ( ! empty( $post->post_password ) ) { 			/* translators: %s: Protected post title. */			$prepend = __( 'Protected: %s' ); 			/**			 * Filters the text prepended to the post title for protected posts.			 *			 * The filter is only applied on the front end.			 *			 * @since 2.8.0			 *			 * @param string  $prepend Text displayed before the post title.			 *                         Default 'Protected: %s'.			 * @param WP_Post $post    Current post object.			 */			$protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); 			$post_title = sprintf( $protected_title_format, $post_title );		} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { 			/* translators: %s: Private post title. */			$prepend = __( 'Private: %s' ); 			/**			 * Filters the text prepended to the post title of private posts.			 *			 * The filter is only applied on the front end.			 *			 * @since 2.8.0			 *			 * @param string  $prepend Text displayed before the post title.			 *                         Default 'Private: %s'.			 * @param WP_Post $post    Current post object.			 */			$private_title_format = apply_filters( 'private_title_format', $prepend, $post ); 			$post_title = sprintf( $private_title_format, $post_title );		}	} 	/**	 * Filters the post title.	 *	 * @since 0.71	 *	 * @param string $post_title The post title.	 * @param int    $post_id    The post ID.	 */	return apply_filters( 'the_title', $post_title, $post_id );}

History

Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/post-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.