14+ years building on WordPress / Replies in under 5 hours
WordPress 1 min read · Updated July 2026

How to get the title in WordPress template page

AK
Ajay Khandal
WordPress Developer
TL;DR

WordPress gives you two built-in functions for pulling a post's title into a template: get_the_title(), which returns the title as a string (optionally for a specific post ID) so you can use it in custom markup, and the_title(), which echoes the current post's title directly and can wrap it with optional before/after markup. Which one to use depends on whether you need to manipulate the title before output or just print it as-is.

Getting the title on a template page is a very common requirement when creating templates in WordPress. There are two main functions you can use:

  1. get_the_title()
  2. the_title()

get_the_title()

get_the_title( int|WP_Post $post )

You can pass a post ID in the parentheses to get a specific post’s title. By default, it uses the current $post.

the_title()

the_title( string $before = '', string $after = '', bool $echo = true )

Displays or retrieves the current post title with optional markup.

Parameters

$before (string, optional)
Markup to prepend to the title. Default: ''.
$after (string, optional)
Markup to append to the title. Default: ''.
$echo (bool, optional)
Whether to echo or return the title. Default: true (echo).

Examples

<?php echo get_the_title( $post_id ); ?>

<?php the_title(); ?>

Difference between the_title() and echo get_the_title()

The two are not 100% identical, though they are close and give the same results in most cases.

  • the_title() will echo the title by default, but the third parameter ($echo) can be used to change that behavior.
  • the_title() prepends the optional $before and appends the optional $after arguments to the output.

Looking to round out your WordPress knowledge? Learn more about how to use wp_get_attachment_image() in your templates. Learn more about the right way to enqueue scripts and styles in WordPress.

AK

Written by Ajay Khandal

WordPress Developer — building, fixing and speeding up WordPress sites.

Work with me →