How To Archive WordPress Posts and Pages

What do you do with published WordPress content that you want to remove from public view but don’t want to trash?

You archive it. Simple. Well, no. Functionality that arguably should either be built-in or definitely should be easy to implement is actually unnecessarily difficult. It also doesn’t help that WordPress muddies the waters by using the archive term for older posts.

In this article, I’ll show you how you can archive content using the Edit Flow plugin to do the heavy lifting.

Photo of an archive
Archiving is an important but missing part of WordPress

Note: The approach described in this article applies to posts, pages and custom post types. I’ve used the term “post” simply for convenience.

To provide archiving, we need to add another step to the end of the publishing process, an option after “published”, by adding a new post status of “archived”. Archiving posts is then a simple matter of changing the post status to the new status and ensuring that the archived post does not appear anywhere on the site, including in search results and menus.

WordPress has eight built-in post statuses and adding to the list is very easy. However, simple tasks such as adding the new status to the post status drop-down in the Publish meta box on the post edit screen is frustratingly difficult. With no helpful filter or action available within WordPress itself, the most common solution uses JQuery-assisted HTML acrobatics to force new statuses into the user interface in the browser. Not exactly development best practice.

Fortunately, the Edit Flow plugin can help us extend the publishing workflow whilst avoiding client-side HTML wrangling.

Install the Edit Flow Plugin

Edit Flow has plenty of great features for managing posts in a team environment. We won’t go into them here but I’d recommend reading Paul Kaiser’s review of Edit Flow here on WPMU.org.

Switch Off Unused Modules

For now, we just need to have Edit Flow’s Custom Statuses module enabled, so once installed, click on Edit Flow in the main menu and disable all modules except for Custom Statuses.

Screen grab of the Edit Flow modules management screen
For archiving you only need Custom Statuses but check out the other modules too

Configure the statuses

Screen grab showing the updated Status
The updated Status dropdown

Click on Custom Statuses and,

  1. Make the Draft status the default status by hovering your mouse over “Draft” and clicking on the “Make Default” menu option.
  2. Delete all the statuses except for Draft (again, roll your mouse over the status and click on the Delete menu option).
  3. Use the “Add New” form to add a new custom status of “Archived”. Click on the “Options” tab and select the post types that you want to be able to archive – custom post types are available as well.

Now, in the Publish meta box on the post edit screen, the Status drop down will show the Custom Statuses, including the new Archived status.

To archive a post, simply select “Archived” and click on “Update”. This will remove the post from the front-end, including searches. You’ll also see that an “Archived” link, complete with post count, is added to the status links at the top of the post list page, giving you quick and easy access to the archived posts

Screen grab showing Archived in the post status links on the post listing screen
The new Archived link added to the post list screen

But what about Menus?

WordPress ignores the status when it comes to building menus. If you’ve put a page in the menu then it will be shown even if its status is archived or, indeed, draft.

To save you having to check your menus every time you archive a page, use this code either in your functions.php file or in a simple plugin:

{code}

function remove_archived_from_menu($post) {
_wp_delete_post_menu_item($post->ID);
}
add_action( ‘publish_to_archived’, ‘remove_archived_from_menu’);

{/code}

This hooks into the status change action that is fired every time a post changes status. In this case we are interested in the change from “publish” to “archive” (draft items are unlikely to be in a menu). When that change occurs we want to delete any menu item with the post’s ID.

Archiving content is a fairly basic function of a content management system and it’s a little surprising that WordPress doesn’t already have this facility built-in. Rolling your own solution is cumbersome and the simplest solution is a hack that would not sit well with most developers.

Using Edit Flow to provide archiving is a straight-forward, hack-free solution that not only provides simple archiving functionality but also an introduction to a powerful content management plugin.

Are you already archiving content? How do you do it? Tell us in the comments below.

Photo credit: Hannes Grobe