Hiding a WordPress MetaBox – Without Disabling It

On a few WordPress projects I’ve needed to make use of a taxonomy for organizational/archive purposes that are a bit…out of the ordinary.

In one example a taxonomy term was used to create year based archives – but the taxonomy was assigned (and created) based on a combination of custom fields that were selected.

In another example, the term was used to define the source of the content that was automated to import into WordPress through a cron job.

In both examples the taxonomy terms are critical for the project/site’s basic functionality but, they are also not something a user should be editing or modifying willy-nilly.

As anyone who debugs software knows, sometimes hiding things like this can lead to posts ending up in impossible cases so it’s nice to be able to provide an end-user (or admin, depending on the project) with a back door to be able to view and correctly assign terms.

Enter the hidden_meta_boxes filter. Using the snippet below, adjust your post type and taxonomy slugs in order to default the meta box to be hidden.

 * Always force hiding the year taxonomy metabox.
 * This still keeps it available for a user to open through
 * screen options - the display state is not persisted once
 * they leave the page's session.
 * @param array     $hidden List of hidden metaboxes.
 * @param WP_Screen $screen The active admin screen.
 * @return array
function tacreative_default_hide_years( $hidden, $screen ) {

    $post_type_slug = 'magazine_issue';
    $taxonomy_slug = 'calendar_year';

    if (
        'edit' === $screen->parent_base
        && $post_type_slug === $screen->post_type
    ) {
        $hidden[] = $taxonomy_slug . 'div';
    return $hidden;
add_filter( 'hidden_meta_boxes', 'tacreative_default_hide_years', 10, 2 );

Additional Taxonomy Features

If you’re looking to add a dropdown on the admin page so users can filter by this custom taxonomy check out the article Custom Post Type Filter Admin By Custom Taxonomy