Using WordPress ‘get_the_title()’ PHP function

The get_the_title() WordPress PHP function retrieves the post title.

Usage

echo get_the_title( $post );

Parameters

  • $post (int|WP_Post) – Optional. Post ID or WP_Post object. Default is the global $post.

More information

See WordPress Developer Resources: get_the_title()

Examples

Display the current post’s title

echo get_the_title();

Display the post title as a link

echo '<a href="' . get_the_permalink() . '" title="' . the_title_attribute( array( 'echo' => false ) ) . '">' . get_the_title() . '</a>';

Display the post title with HTML escaping

echo esc_html( get_the_title() );

Display the post title with allowed HTML tags

echo wp_kses_post( get_the_title() );

Simple breadcrumb trail for pages, two levels deep

echo '<div class="breadcrumb">';
$parent_title = get_the_title( $post->post_parent );
if ( $parent_title != the_title( ' ', ' ', false ) ) {
    echo '<a href="' . esc_url( get_permalink( $post->post_parent ) ) . '" alt="' . esc_attr( $parent_title ) . '">' . $parent_title . '</a> » ';
}
echo '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark" alt="' . esc_attr( get_the_title() ) . '">' . get_the_title() . '</a>';
echo '</div>';