How to add a drafts link to your WordPress posts menu with a plugin

Update January 1, 2022 (Happy New Year):

Cindi wrote in asking how to restrict the link to “drafts” in the menu to admin-level users only. I accomplished this by tucking the function inside an “if” statement that reads like this: “if(current_user_can( ‘administrator’ )){……[rest of code….].”

Below is the full, new function restricting the link to drafts to admin-level users only:

<?php

/*
Plugin Name: Drafts Link in Posts Menu
Plugin URI: https://davidwalsh.name/wordpress-admin-add-menu-item
Description: Adds a link to draft items from the Posts admin menu. hellotumo.com took David's work and made it into a plugin. Version 2 restricts to admin users only.
Version: 2.0
 */

function add_drafts_admin_menu_item() {

if(current_user_can( 'administrator' )){
  add_posts_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&post_type=post');
  add_pages_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&post_type=page');
  } /*close if statement*/

} /*close whole function*/

add_action('admin_menu', 'add_drafts_admin_menu_item');

?>

David Walsh has the secret sauce for getting a link to your post drafts in the posts menu option of your WordPress site. Yes!

I built upon his work and created a custom plugin that does the same. Why?

Because I hate it when a site update wipes out my functions.php custom code. By using a plugin, you can keep this handy-dandy shortcut secure amid the next upgrade.

To do this, just copy the code below into a text file, save it as yourspecialsecretsauce.php, drop it into your plugins directory, and activate it. The original full code of version 1 is below:

<?php

/*
Plugin Name: Drafts Link in Posts Menu
Plugin URI: https://davidwalsh.name/wordpress-admin-add-menu-item
Description: Adds a link to draft items from the Posts admin menu. hellotumo.com took David's work and made it into a plugin.
Version: 1.0
 */

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&amp;post_type=post');
  add_pages_page(__'Drafts'), __('Drafts'), 'read', 'edit.php?post_status=draft&amp;post_type=page');
} */

  // $page_title, $menu_title, $capability, $menu_slug, $callback_function
  add_posts_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&amp;post_type=post');
  add_pages_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&amp;post_type=page');
}

add_action('admin_menu', 'add_drafts_admin_menu_item');

?>

5 thoughts on “How to add a drafts link to your WordPress posts menu with a plugin”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.