Home WordPress General Functions wp_title() WordPress wp_title() Function 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.
<title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title> Call What 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 wp_title( string $sep = '»', bool $display = true, string $seplocation = '' ): string|void Parameters Parameter Description $sepstring. The separator between the title and the next text. Default is ». $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 Value Description void When $display is true, the title is printed. string When $display is false, the title is returned.
WordPress Examples Three short theme examples. Each one shows the code and what it prints.
1. A classic title tag 2. Return the title 3. The modern way Example 1 — A classic title tag Print the page title and the site name.
<title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title> On the post "Hello World":
<title>Hello World | My Blog</title>
On the front page (latest posts):
<title>My Blog</title> How It Works wp_title() prints "Hello World | " (separator on the right).bloginfo( 'name' ) adds the site name.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.
<?php
$title = wp_title( '', false );
echo '<h1>' . esc_html( trim( $title ) ) . '</h1>'; On /about/:
<h1>About Us</h1> How It Works false returns the title instead of printing.The separator is empty, so only the title is left. trim() removes extra spaces around it.Example 3 — The modern way Let WordPress print the title tag for you.
<?php
function mytheme_setup() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'mytheme_setup' ); WordPress prints in the head:
<title>Hello World – My Blog</title>
(no title tag is needed in header.php) How It Works title-tag support tells WordPress to manage the title.Remove the old <title> line from header.php. Plugins can now change the title safely. Frequently Asked Questions What does wp_title() do? It prints or returns the title of the current page. It was used inside the title tag in older themes.
Should I still use wp_title()? For new themes, no. Use add_theme_support( 'title-tag' ). You will still see wp_title() in older themes.
How do I put the separator after the title? Pass right as the third argument: wp_title( '|', true, 'right' ).
Why is the title empty on my home page? With latest posts as the front page, there is no page title. Add the site name yourself with bloginfo( 'name' ).
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion