A better WordPress admin title.

At least for me!

Categories: Development, WordPress

At the moment I have 5 posts open to edit. Looking at them, all I see is “Edit Post < Adam Patterson – WordPress“.

Sure 5 tabs aren’t that many and not that hard to sort through but I began to wonder why WordPress wouldn’t simply show the post title for pages and posts.

Lucky for me, it wasn’t that hard.

First, we need to create a new filter that will be called when the admin page title is generated. This filter is called admin_title.

Next we will pull a few variables out of the global scope $post, $title, $action, $current_screen.

After we check that we are on the admin page and that the action is edit and not add. All that is left to do is make sure we are in the context of editing a post or a page. I supposed you could go farther by doing some experimenting here but this suited my needs just fine.

Lastly, structure your page title to suit you.

I ended up with “Edit Post < Post Name – Adam Patterson” or “Edit Page < Post Name – Adam Patterson“.

I suppose the purists might want to keep WordPress in the title, but it’s long enough that I don’t see it as is so I am good without.

Simply add the following code to your themes functions.php file and you are all set!

add_filter('admin_title', 'better_admin_title', 10, 2);

function better_admin_title($admin_title, $title)
{
    global $post, $title, $action, $current_screen;
    if (is_admin() and $action == 'edit' and in_array($current_screen->id, ['post', 'page'])) {
        return $title . ' ‹ ' . $post->post_title . ' — ' . get_bloginfo('name');
    }

    return $admin_title;
}

Read more about admin_title


Adam Patterson

Adam Patterson

User Interface Designer & Developer with a background in UX. I have spent 5 years as a professionally certified bicycle mechanic and ride year-round.

I am a husband and father of two, I enjoy photography, music, movies, coffee, and good food.

You can find me on Twitter, Instagram, and YouTube!