Add Menu Items to the WordPress Admin Menu

By  on  

The existing menus in WordPress are solid but one annoyance is that I need to click "All Posts" and then the "Drafts" link to get to my drafts; I simply want to get there as quickly as possible via the Posts menu. I did some quick research on the topic and in two minutes I was able to add a "Drafts" submenu item to the "Posts" menu. Here's how I did it!

Within the functions.php file of my current theme (this file gets loaded even for admin!), I added the following:

// Add menu item for draft posts
function add_drafts_admin_menu_item() {
  // $page_title, $menu_title, $capability, $menu_slug, $callback_function
  add_posts_page(__('Drafts'), __('Drafts'), 'read', 'edit.php?post_status=draft&post_type=post');
}
add_action('admin_menu', 'add_drafts_admin_menu_item');

The add_posts_page method is actually a shortcut for add_submenu_page, which allows you to add a submenu item for any existing menu item. And WordPress allows you to get pretty detailed with your own menus, as you can see here.

This added "Drafts" link will save me click after click after click throughout my time using WordPress. Take the few moments to add links to existing menus as you'd like -- there's nothing like a fresh shortcut to get you moving faster!

Recent Features

  • By
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

  • By
    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I've even caught myself reading the post...

Incredible Demos

  • By
    Control Element Outline Position with outline-offset

    I was recently working on a project which featured tables that were keyboard navigable so obviously using cell outlining via traditional tabIndex=0 and element outlines was a big part of allowing the user navigate quickly and intelligently. Unfortunately I ran into a Firefox 3.6 bug...

  • By
    Disable Autocomplete, Autocapitalize, and Autocorrect

    Mobile and desktop browser vendors do their best to help us not look like idiots by providing us autocomplete, autocorrect, and autocapitalize features.  Unfortunately these features can sometimes get in the way;  we don't always want or need the help they provide.  Luckily most browsers allow...

Discussion

  1. Aside from what David has put up, you can quite simply create a section under Posts, which does the exact same thing and will conveniently house posts related to that section.

    By default, Post types are called ‘post’ and Page types are ‘page’ but what the code in my site does it shows you that you can customise the Admin panel without worrying about theming things.

    Happy reading!

    http://mynameisdonald.com/add-a-new-post-type-section-in-wordpress/

  2. Thats nice, every shortcut counts. One things comes to mind: you should include the translation string for ‘Drafts’ instead of hard coding it. That way this code would be usefull for ppl that runt wordpress in other languages than english.

  3. Thanks for sharing this code with us. The idea is good as it is very annoying. Could you please let me know that whether this code works only in any specific theme or can work in any theme?

  4. Again on localization/translation. You should update you code to read:

    add_posts_page(__('Drafts') , __('Drafts') , 'read', '?post_status=draft&post_type=post');
  5. Bassel

    it just didn’t work for me as mentioned
    i had to add (edit.php)
    to the code (?post_status=draft&post_type=post) to be just like this
    edit.php?post_status=draft&post_type=post

    after that it works fine.
    is there any explanation regarding it

    Thanks

  6. Joki

    Hi There, nice one,

    I’m using Easy Options Page (http://wordpress.org/plugins/easy-options-page/) plugin to create an option page, and the Easy Admin Menu (http://wordpress.org/plugins/easy-admin-menu/) to reorder and hide some elements from the Admin Menu panel.

    Hope this helps!

  7. Thanks a lot for this, clicking on “All Posts”, then “Drafts” was driving me insane!

  8. This is exactly what I needed! My only wish is I wish add_posts_page had a parameter for placement so the menu item can be conveniently placed before Categories/Tags. Oh well. Thanks for the code snippet! :-)

  9. Hi, Thank you for this tip, very good. I would like to know if there’s any way to repeat this way to make more menus? I tried but it’s bring me an error. Thanks in advance!

  10. Andy

    This is EXACTLY what I was looking for. I don’t know why it’s not this quick and easy to get to Drafts by default, but your solution was almost as quick and easy – thanks!

  11. Good stuff! I turned this into a plugin so I don’t have the code wiped out in functions.php when I update my WordPress installation. You can find the plugin here ==> http://hellotumo.com/2018/03/11/how-to-add-a-drafts-link-to-your-wordpress-posts-menu-with-a-plugin/

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!