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:
- apply_filters( protected_title_format )filterline 141 (+23 into the body)
Filters the text prepended to the post title for protected posts.
- apply_filters( private_title_format )filterline 160 (+42 into the body)
Filters the text prepended to the post title of private posts.
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
- WP_Comments_List_Table::column_response()Outputs the response column.
- WP_REST_Global_Styles_Controller::prepare_item_for_response()Prepare a global styles config output for response.
- WP_REST_Post_Search_Handler::prepare_item()Prepares the search result for a given post ID.
- WP_REST_Posts_Controller::prepare_item_for_response()Prepares a single post output for response.
- WP_REST_Revisions_Controller::prepare_item_for_response()Prepares the revision for the REST response.
- WP_Widget_Recent_Comments::widget()Outputs the content for the current Recent Comments widget instance.
- WP_Widget_Recent_Posts::widget()Outputs the content for the current Recent Posts widget instance.
- Walker_Nav_Menu_Edit::start_el()Start the element output.
- _WP_Editors::wp_link_query()Performs post queries for internal linking.
- _draft_or_post_title()Gets the post title.
- _wp_ajax_menu_quick_search()Prints the appropriate response to a menu quick search.
- block_core_breadcrumbs_get_post_title()Gets a post title with fallback for empty titles.
Show all 47
- comments_popup_link()Displays the link to the comments for the current post ID.
- get_adjacent_image_link()Gets the next or previous image link that has the same post parent.
- get_oembed_response_data()Retrieves the oEmbed response data for a given post.
- get_post_embed_html()Retrieves the embed code for a specific post.
- get_the_privacy_policy_link()Returns the privacy policy link with formatting, when applicable.
- get_the_title_rss()Retrieves the current post title for the feed.
- render_block_core_comments_title()Renders the `core/comments-title` block on the server.
- render_block_core_latest_posts()Renders the `core/latest-posts` block on server.
- render_block_core_post_comments_link()Renders the `core/post-comments-link` block on the server.
- render_block_core_post_featured_image()Renders the `core/post-featured-image` block on the server.
- render_block_core_post_title()Renders the `core/post-title` block on the server.
- render_block_core_read_more()Renders the `core/read-more` block on the server.
- the_title()Displays or retrieves the current post title with optional markup.
- the_title_attribute()Sanitizes the current title when retrieving or displaying.
- trackback_rdf()Generates and displays the RDF for the trackback information of current post.
- twenty_twenty_one_entry_meta_footer()Prints HTML with meta information for the categories, tags and comments.
- twentyfifteen_entry_meta()Prints HTML with meta information for the categories, tags.
- twentyfifteen_excerpt_more()Replaces "[.
- twentyfifteen_post_thumbnail()Displays an optional post thumbnail.
- twentyfourteen_excerpt_more()Replaces "[.
- twentyfourteen_post_thumbnail()Displays an optional post thumbnail.
- twentynineteen_comment_count()Prints HTML with the comment count for the current post.
- twentynineteen_entry_footer()Prints HTML with meta information for the categories, tags and comments.
- twentynineteen_excerpt_more()Replaces "[.
- twentyseventeen_edit_link()Displays an accessibility-friendly link to edit a post or page.
- twentyseventeen_excerpt_more()Replaces "[.
- twentysixteen_entry_meta()Prints HTML with meta information for the categories, tags.
- twentysixteen_excerpt_more()Replaces "[.
- twentythirteen_excerpt_more()Replaces "[.
- twentytwenty_edit_post_link()Filters the edit post link to add an icon and use the post meta structure.
- twentytwenty_read_more_tag()Overwrite default more tag with styling and screen reader markup.
- wp_embed_excerpt_more()Filters the string in the 'more' link displayed after a trimmed excerpt.
- wp_latest_comments_draft_or_post_title()Get the post title.
- wp_prepare_revisions_for_js()Prepare revisions for JavaScript.
- wp_xmlrpc_server::_prepare_comment()Prepares comment data for return in an XML-RPC object.
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.
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.