Declutter your WordPress page admin with a new status type.

Some WordPress sites contain far too many pages that neither can be deleted (yet) or should be public. So what do you do with these types of pages? My solution allows you to keep the content and archive the page. That means creating a new page-status type named “archived”. Below is how to achieve this and declutter your page admin. Just add this to your functions.php and give it a go.

/**
 * Add a new page status type.
 */
function mplmnt_custom_page_status(){
	register_post_status( 'archived', array(
		'label'                     => _x( 'Archived', 'post' ),
		'label_count'               => _n_noop( 'Archived <span class="count">(%s)</span>', 'Archived <span class="count">(%s)</span>'),
        'public'                    => false,
        'internal'                  => true,
        'protected'                 => true,
        'private'                   => false,
        'exclude_from_search'       => true,
        'publicly_queryable'        => false,
        'show_in_admin_all_list'    => false,
        'show_in_admin_status_list' => true,
	));
}
add_action( 'init', 'mplmnt_custom_page_status' );

/**
 * Append Archived in the status dropdown type.
 */
function mplmnt_status_into_inline_edit() {
	echo "<script>
	jQuery(document).ready( function() {
		jQuery( 'select[name=\"_status\"]' ).append( '<option value=\"archived\">Archived</option>' );
	});
	</script>";
}
add_action('admin_footer-edit.php','mplmnt_status_into_inline_edit');

/**
 * Set label.
 */
function mplmnt_display_status_label( $statuses ) {
	global $post;
	if( get_query_var( 'post_status' ) != 'archived' ){
		if( $post->post_status == 'archived' ){
			return array('Archived');
		}
	}
	return $statuses;
}
add_filter( 'display_post_states', 'mplmnt_display_status_label' );

/**
 * Add submenu to Pages.
 */
function mplmnt_add_status_to_page_menu() {
	add_submenu_page( 
        'edit.php?post_type=page', 
        __( 'Archived', 'textdomain' ), 
        __( 'Archived', 'textdomain' ), 
        'manage_options', 
        'edit.php?post_status=archived&post_type=page' 
    );
}
add_action( 'admin_menu', 'mplmnt_add_status_to_page_menu' );

/**
 * Custom slug callback.
 */
function mplmnt_update_slug_callback( $post_id ) {
    // verify post is not a revision
    if ( ! wp_is_post_revision( $post_id )) {
        remove_action( 'save_post', 'mplmnt_update_slug_callback' );
        if ( get_post_status ( $post_id ) == 'archived' ) {
            $slug = 'archived-'.get_post_field( 'post_name', $post_id );
            wp_update_post( array(
                'ID' => $post_id,
                'post_name' => $slug
            ));
        }
        add_action( 'save_post', 'mplmnt_update_slug_callback' );
    }
}
add_action( 'save_post', 'mplmnt_update_slug_callback' );