Filter Hook since 0.71

the_title

Filters the post title

Description

the_title changes how a title is displayed, not the value in the database. Guard with post ID so menus and admin lists are not rewritten by accident.

When it runs

Whenever the_title() or get_the_title() runs with the filter on — loops, menus, and some admin screens.

Signature

apply_filters( 'the_title', string $title, int $id );

Parameters

  • $title string — The post title.
  • $id int — Post ID.

Examples

Basic

add_filter( 'the_title', function( $title, $id ) {
    if ( get_post_type( $id ) === 'book' ) {
        return 'Book: ' . $title;
    }
    return $title;
}, 10, 2 );

Prefix titles for one post type only.

Real case

add_filter( 'the_title', function( $title, $id ) {
    if ( ! is_admin() && empty( $title ) ) {
        return __( '(Untitled)', 'my-textdomain' );
    }
    return $title;
}, 10, 2 );

Show a fallback label instead of a blank title on the front-end.

Common Use Cases

  • Prefix/suffix titles by post type
  • Truncate long titles
  • Add icons or labels to titles
  • Translate titles dynamically

Common mistakes

  • Altering titles in nav menus because the filter also runs there — check in_the_loop() or post type

Related hooks

FAQ

Why did the_title also change my menu item labels?

The filter runs anywhere get_the_title()/the_title() is called, including some menu-label code paths. Check the post type or scope the condition more tightly.

Source: wp-includes/post-template.php

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

the_title → the_content

functions.php — the_title
functions.php
PHP the_title · Hook 1 of 2 · Step 1 of 7

Practice the the_title WordPress filter hook in our interactive sandbox — a VS Code-style editor with a step-by-step the_title tutorial, add_filter exercises, and instant feedback. No local WordPress install required.