WordPress wp_title() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, wp_title() prints (or returns) the title of the current page, such as a post title, a category name, or "Search Results". Older themes used it inside the <title> tag.

Modern themes usually call add_theme_support( 'title-tag' ) and let WordPress print the <title> tag. Learn wp_title() anyway, because many existing themes still use it.

Syntax

Use it inside the title tag, then add the site name.

WordPress
<title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title>
CallWhat it does
wp_title()Prints the title with a leading » separator.
wp_title( '|', true, 'right' )Prints "Title | " with the separator on the right.
wp_title( '|', false )Returns the title instead of printing.

On the front page with latest posts, the page title is empty, so only the site name shows.

Full declaration
WordPress
wp_title( string $sep = '&raquo;', bool $display = true, string $seplocation = '' ): string|void

Parameters

ParameterDescription
$sepstring. The separator between the title and the next text. Default is &raquo;.
$displaybool. true (default) prints the title. false returns it.
$seplocationstring. right puts the separator after the title. Any other value puts it before. Default is empty.

Return Value

Return ValueDescription
voidWhen $display is true, the title is printed.
stringWhen $display is false, the title is returned.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — A classic title tag

Print the page title and the site name.

WordPress
<title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title>

How It Works

  1. wp_title() prints "Hello World | " (separator on the right).
  2. bloginfo( 'name' ) adds the site name.
  3. On the front page the title is empty, so only the site name remains.

Example 2 — Return the title

Use the title in a heading.

WordPress
<?php
$title = wp_title( '', false );
echo '<h1>' . esc_html( trim( $title ) ) . '</h1>';

How It Works

  1. false returns the title instead of printing.
  2. The separator is empty, so only the title is left.
  3. trim() removes extra spaces around it.

Example 3 — The modern way

Let WordPress print the title tag for you.

WordPress
<?php
function mytheme_setup() {
  add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'mytheme_setup' );

How It Works

  1. title-tag support tells WordPress to manage the title.
  2. Remove the old <title> line from header.php.
  3. Plugins can now change the title safely.

Frequently Asked Questions

It prints or returns the title of the current page. It was used inside the title tag in older themes.
For new themes, no. Use add_theme_support( 'title-tag' ). You will still see wp_title() in older themes.
Pass right as the third argument: wp_title( '|', true, 'right' ).
With latest posts as the front page, there is no page title. Add the site name yourself with bloginfo( 'name' ).

Back to the General Functions index

Browse every WordPress general function in one table.

General Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful