Like the blog? Get the book »

Change Quick Action Button in Admin

Change Quick Action Button in Admin

You know the “quick action” button in the WordPress admin? It’s a darn useful little UI touch. At the Dashboard, the default is “New Post”. But depending on where you are in the Admin, the default of it changes. In general it’s really helpful. For example when you are in the Plugins area, the default is Install Plugins:

WordPress Quick Action MenuDefault action being smart

A while ago I was moaning about one particular area where I didn’t find the default being so smart. When you publish a new Post, the default goes to New Post. To me it would make sense when you publish a new Page to have that button be New Page. If you have a WordPress site where you publish a lot of pages, you can feel me.

Reader Otto let me know there is a way you can change this. Here is Otto:

Adding the New Page as default there is actually rather simple.

Look in wp-admin/includes/template.php. Down towards the bottom of the file, you’ll find the function favorite_actions().

In that function, it reads the wp-admin page name and sets a $default_action based on that. For example, when you’re looking at the edit-pages.php screen, the default action becomes “New Page”.

The Page editor screen is page.php. Note that it has no default action. To give it one, simply add a case ‘page.php’: in the correct place. You can add it directly before that case ‘edit-pages.php’ if you want the default action to be the same New Page link.

If you want this change made to core, then I suggest making an Enhancement ticket to that effect on the WordPress trac. As always search first, somebody else might have already made that ticket request.

So to fix my particular gripe, I just opened the file at the path mentioned above and found the favorite_actions function. It’s a pretty readable function, and adding a new bit to change the behavior is pretty easy. I just added this right above the one for edit-pages.php

case 'page.php':
   $default_action = array('page-new.php' => array(__('New Page'), 'edit_pages'));
   break;
WordPress Quick Action Menu (improved version)Fixed!

Important notes

This is what you would call a “core hack”. Meaning that next time you upgrade WordPress, this code will be gone. It doesn’t mean “don’t do it” and it especially doesn’t mean “do it and don’t upgrade”. It means that you should make a note somewhere handy to yourself that when you do upgrade, you can see if it’s fixed and if it’s not, make the same alteration again.

Also as Otto suggested, there is an official channel for getting stuff done like this, the WordPress trac. I’ve never submitted anything there before, but to put my money where my mouth is I opened a ticket.

6 responses

  1. I’m not really sure I see the point in this – as you can just click ‘New Page’ over on the left anyway… I’m sure it has its use for a few people, but what’s the difference, for most of us, between clicking a link at the top, or a link on the left?

    • Nothing really. It’s fairly trivial. But in my own link-clicking muscle memory it trips me up fairly often. And since the “Write Post” and “Write Page” screens are visually nearly identical, it can often have consequences. Let’s say I was creating some test pages for something on this website. I created a new page, published it, wanted to create another one, hit the button, typed in some totally fake content like “blah blah stupid fake content” and published that. Oh no! That was really a post. Well too late, it’s already out on the RSS feed and I look like an idiot.

      I see this as kind of a “mistake” based on the behavior of how that quick action button works elsewhere, so might as well fix it.

  2. why edit core files when you can put it into your functions.php file

    function my_favorite_action( $actions ) {
    	$actions[ wp_nonce_url( 'edit-comments.php', 'wp-cache' ) ] = array( __( 'Manage Comments' ), 'manage_options' );
    	return $actions;
    }
    add_filter( 'favorite_actions', 'my_favorite_action' );
    • ‘Cause I didn’t know how to do that. I’m a noob when it comes to this plugin/functions/filtering stuff, although I’m getting the hang of it better. Thanks for the idea, looks like it will need a little editing to replicate exactly my scenario.

  3. I really need this thankss…many thanks .

  4. Whether or not I would use this particular thing, it’s still interesting and helps me learn more about wordpress, so thanks.

    My question for you, prompted by your tip here, is this: can I make My Favorites *always* have a link to the stylesheet so I can whip over and edit it? When I’m setting up a new site, I’m editing this file all the time! But it’s hard to get to, since I work on a small laptop and the file is at the veeeerrrrry bottom of the Editor page. Every time I open my Editor (under Appearance), I have to scroll, scroll, scroll past files I never open, to see the stylesheets at the very bottom.

    I suppose I should just work in a code editor like everyone else, but I wish I could just stick it into the My Favorites dropdown like you’re doing here with New Page. Easy or hard to do that?

    It’s okay if this is too far afield to answer here. Just wondering if it’s something a person with very rudimentary php knowledge should try at home or if it’ll bork my whole core. Well, not *my* whole core, but my site’s whole core. :)

Comments are closed for this post. Contact us with any critical information.
© 2009–2024 Digging Into WordPress Powered by WordPress Monzilla Media shapeSpace