Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Adam Patterson
Adam Patterson

Posted on • Originally published atadampatterson.ca

     

A better WordPress admin title.

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 calledadmin_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 themesfunctions.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 aboutadmin_title

Top comments(5)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
bueltge profile image
Frank Bültge
Human, Papa, Alpinist, Cyclist
  • Location
    Earth, Germany, Jena
  • Joined

Great idea for visibility, however a small hint - you should not add this to the functions.php of the Theme. A simple plugin should much more helpful because the topic is not in context with the front-end so that should be independent from the Theme.

CollapseExpand
 
adampatterson profile image
Adam Patterson
Husband, Father, Maker of things, writer of code, Cyclist, Eater of snacks.
  • Email
  • Location
    Edmonton, Canada
  • Education
    School
  • Work
    Lead Developer / Innovation
  • Joined

Good point, I tossed it in there as a proof of concept but could easily add it to a function and I will :)

I like your comment on the Context of Fron End Dev, How do you feel about how Gutenberg blocks are created for custom themes?

CollapseExpand
 
bueltge profile image
Frank Bültge
Human, Papa, Alpinist, Cyclist
  • Location
    Earth, Germany, Jena
  • Joined

It more in the context of the theme. If the block is only for design, formatting so should it leave inside the Theme. However is also possible as plugin, because so it is possible to use after a switch of the theme or separately. But is the block a part of data, they're stored inside the database and have more a topic of data, not only design so should it a separate plugin, not inside the theme. It makes also much more easy to update them.

CollapseExpand
 
tammalee profile image
Tammy Lee
I'm a generalist who loves problem solving and team-building. Currently obsessed with the practical applications of AI and using AI to assist with coding.
  • Location
    Canada
  • Work
    Software Development/Engineering Manager
  • Joined

This was a great idea! Awesome!

CollapseExpand
 
adampatterson profile image
Adam Patterson
Husband, Father, Maker of things, writer of code, Cyclist, Eater of snacks.
  • Email
  • Location
    Edmonton, Canada
  • Education
    School
  • Work
    Lead Developer / Innovation
  • Joined

Thanks Tammy!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Husband, Father, Maker of things, writer of code, Cyclist, Eater of snacks.
  • Location
    Edmonton, Canada
  • Education
    School
  • Work
    Lead Developer / Innovation
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp