Hiding Meta Boxes By Default Without Overrides In WordPress

Problem: Meta boxes clutter editing screens

As you add plugins and functionality to your WordPress site, the editing screens can quickly become cluttered with meta boxes. These extra boxes crowd the screen and make it harder for content editors to focus on the post content itself.

Having a cluttered editing screen leads to a few key problems:

  • Editing focus is lost as editors get distracted by extra options
  • Screen space is limited, pushing post content down
  • Page load times increase with extra boxes
  • It’s overwhelming for new editors when learning the system

Cleaning up the editing interface is crucial for easy site management. Hiding unnecessary meta boxes by default helps create that clean experience for your team.

Solution: Hide meta boxes with code

Luckily, WordPress gives you control over which meta boxes appear by default. With a few lines of code, you can hide boxes across all post types or target specific ones you don’t need.

The best approach is to hide meta boxes by default, then selectively show ones as needed with overrides. This prevents clutter while allowing access if editors need it.

In this article, we’ll explore functions to hide meta boxes, global and post type specific solutions, potential issues, and additional management tips.

Functions to Hide Meta Boxes

WordPress has two main functions for managing meta boxes:

  • remove_meta_box() – Hides existing meta boxes
  • add_meta_box() – Adds back hidden meta boxes

We’ll focus first on remove_meta_box() to hide those unnecessary meta boxes for a cleaner interface.

remove_meta_box()

The remove_meta_box() function allows you to hide an existing meta box from any editing screen. It takes these parameters:

  • $id – Unique ID of the meta box
  • $screen – The screen to hide it from
  • $context – The context it appears in (advanced, side, etc.)

Here is basic usage where you pass the ID and screen:

remove_meta_box( 'my_meta_box_id', 'post' ); 

And to be more specific about context as well:

 
remove_meta_box( 'my_meta', 'post', 'normal' );  

This will look for my_meta in the normal context on the post edit screen and hide it.

Examples of usage

Some common meta boxes you may want to hide include:

// Hide slug box
remove_meta_box( 'slugdiv', 'post', 'normal' );

// Hide featured image box  
remove_meta_box( 'postimagediv', 'post', 'side' );

// Hide page attributes box
remove_meta_box( 'pageparentdiv', 'page', 'side' ); 

This cleans up some defaults from core WordPress. But you can use this for just about any meta box a plugin may add as well.

Hiding Meta Boxes for All Post Types

If you want to hide a meta box globally, you can target the special ‘_all’ post type. This allows you to remove meta boxes from all editing screens at once.

Target meta boxes site-wide

The ‘_all’ post type will match any editing screen like posts, pages, or custom post types. For example, to hide a meta box site-wide:

// Hide a meta box from every edit screen
remove_meta_box( 'my_meta', '_all', 'normal' ); 

This is great for removing clutter globally. Just keep in mind it can’t distinguish between screen types.

Examples for common meta boxes

Some meta boxes you may want to hide from all editing screens include:

// Hide discussion box on every screen 
remove_meta_box( 'commentstatusdiv', '_all', 'normal' );  

// Hide tags box globally
remove_meta_box( 'tagsdiv-post_tag', '_all', 'side' );

// Hide slug box everywhere 
remove_meta_box( 'slugdiv', '_all', 'normal' );

This keeps all editing screens clean while preventing distraction from these meta boxes. However, you still may want to show them selectively.

Hiding Meta Boxes for Specific Post Types

Hiding meta boxes globally works great. But sometimes you only want to hide boxes for certain post types. For example, hiding tags on pages but keeping them on posts.

By checking the post type inside conditional checks, you can target specific editing screens.

Conditional checks by post type

WordPress stores the current admin screen in a global variable $typenow. We can check if this matches page, post, or any custom post type.

For example, to check if we are on the post edit screen:

if( $typenow == 'post' ) {

  // Only this will run on post screens
  
}

Using this, we conditionally show or hide meta boxes per type as needed. For example, we can remove unwanted meta boxes when customizing pages:

if( $typenow == 'page' ) {
  
  remove_meta_box( ‘pageparentdiv’, 'pages', ‘side’ );  
  remove_meta_box( 'my-other-box', 'page', 'normal');

}

This cleans up the interface specifically on pages based on your needs.

Examples for page and post meta boxes

Here are some common examples that remove page or post meta boxes separately:

// Only hide on pages: 
if( $typenow == 'page' ) {

  remove_meta_box( 'tagsdiv-post_tag', 'page' );
  remove_meta_box( 'authordiv', 'page' );

}

// Only hide on posts:
if( $typenow == 'post' ) {
  
  remove_meta_box( 'pageparentdiv', 'post' ); 
  remove_meta_box( 'postcustom', 'post' );
  
}

This keeps individual editing screens cleaner while preserving functionality where editors still may need it occasionally.

Caveats Around Hiding Meta Boxes

Before globally removing meta boxes, there are some caveats to consider first.

Considerations around plugins and themes

Many plugins and themes tie custom functionality to their added meta boxes. Just because you hide them visually does not disable this functionality behind the scenes.

For example, removing SEO meta boxes will still leave those fields active and required. Or image uploaders can have issues if you hide their media box associations.

Test functionality thoroughly if removing third party meta boxes. Make sure to consider any ramifications both visually and in terms of features.

When hiding causes issues

Here are some specific areas to test if you run into problems after hiding meta boxes:

  • Permalinks – Ensure any post name fields have not been removed
  • Revisions – Test revisions have not been impacted negatively
  • Required fields – Any required meta may still prevent saving
  • Media uploads – Uploads may not associate properly if that box is hidden

Adjust your removals if anything is broken. The best approach hides boxes by default, then allows selective overriding as needed.

Additional Tips for Meta Box Management

Beyond hiding existing boxes, there are some additional tips for meta box management in WordPress.

Other functions like add_meta_box()

We focused on remove_meta_box() to hide areas by default. But the opposite add_meta_box() function allows you to re-enable hidden meta boxes through code.

Some advanced ways to leverage this include:

  • Only showing a meta box when content editors edit their own posts
  • Building custom administration profiles that enable different meta boxes
  • Crafting simplified and expanded editing modes for beginners vs experts

With creative implementations, you can build highly customized publishing workflows.

Plugin options

If you don’t want to work directly with code, helpful plugins can simplify meta box management as well.

Options like Adminimize and WP Hide Post Types give you admin interfaces to toggle visibility. This allows you to deactivate boxes through checklists rather than coding them.

Try out different solutions to find the right approach that hides distraction while retaining needed functionality.

Leave a Reply

Your email address will not be published. Required fields are marked *