Setting Default Meta Box Visibility For New WordPress Users

The Problem of Overwhelming New Users

When new users first access the WordPress post editor to create content, they are often presented with a large number of meta box options along the right side of the editor. These meta boxes allow the user to input various pieces of information to enhance their posts, such as categories, tags, featured images, excerpts, custom fields, and more.

However having so many meta box options visible by default can overwhelm new users who may not yet understand what these options are for. This could lead to a poor first-time user experience which fails to smoothly guide the user through creating content in WordPress. Some potential downsides include:

  • The user feeling confused and distracted by too many options, making it harder to focus on writing post content itself.
  • The creation process slowing down as the user takes time reading and evaluating each meta box, trying to decide what to put where.
  • The user failing to find and utilize the options actually most essential for their content because they get lost among extraneous choices.

By setting intelligent defaults to show only the most essential meta boxes, we can help streamline the process for new users to have a more guided experience creating WordPress posts and pages.

Using Functions to Set Default Visibility

Fortunately within WordPress, it is simple for developers and site administrators to define default visibility rules for meta boxes. This can be accomplished by using PHP functions inside the main site theme’s functions.php file or a site-specific plugin.

The main meta box visibility functions we can leverage are:

intro_to_using_functions_to_set_defaults()

The intro_to_using_functions_to_set_defaults() function allows developers to tap into WordPress hooks such as add_meta_boxes and default_hidden_meta_boxes which control the visibility and arrangement of meta boxes in the post editor screen.

By adding our own code to functions.php, we can override the default settings and tailor meta box visibility for the specific needs of our site and for particular user roles like new users.

hide_meta_boxes_by_default()

The hide_meta_boxes_by_default() function allows developers to globably hide all meta boxes first, then selectively show only those which new users will need.

This takes a “whitelist” approach where all boxes are hidden upfront, rather than just hiding selected problematic boxes.

show_only_essential_meta_boxes()

Another option is to use the show_only_essential_meta_boxes() function. Rather than hiding all meta boxes first, this will programmatically show only those deemed most necessary when users first access the post editor:

  • Title
  • Content
  • Featured Image
  • Excerpt
  • Discussion

Developers can still allow toggling the visibility of other meta boxes through Screen Options, but by default the editor screen will be simplified significantly for new users.

Example Code for functions.php

Let’s explore some example code that could go inside the main theme or a site plugin’s functions.php file to configure default restrictions on meta boxes for new users.

code_snippet_hide_non_essential_meta_boxes()

function hide_non_essential_meta_boxes() {

  // Hide distracting meta boxes by default for 
  // new users with 'subscriber' role 
  if( current_user_can('subscriber') ) {

    // Array of meta box IDs to hide
    $hide_boxes = array(
      'postcustom',
      'trackbacks', 
      'tagsdiv-post_tag',
      'categorydiv' 
    ); 

    // Loop through boxes to hide
    foreach( $hide_boxes as $box ) {
      remove_meta_box( $box , 'post' , 'normal' );  
    }
  }

}
add_action('do_meta_boxes', 'hide_non_essential_meta_boxes');

code_snippet_set_default_meta_box_visibility()

function set_default_meta_box_visibility() {

  // For new users with 'subscriber' role
  if( current_user_can('subscriber') ) {

    $show_boxes = array('postcustom','trackbacks','postexcerpt','commentstatus','comments');
    
    // 1. Hide All Meta Boxes
    foreach ( array('normal','advanced','side') as $context ) {
      global $wp_meta_boxes;
      unset($wp_meta_boxes[$context]);
    }
    
    // 2. Show allowed boxes
    foreach ( $show_boxes as $box ) {
      add_meta_box( $box , '' , '' , 'post' , 'normal' , 'high' );
    }

  } 

}
add_action('add_meta_boxes', 'set_default_meta_box_visibility');  

Additional Tips for Managing Meta Boxes

Using functions in theme files provides a straightforward way to manage default meta box visibility for new WordPress users. Some additional tips include:

Using plugins to customize meta boxes

In addition to adding code directly, developers can use dedicated plugins like Hide Meta Boxes for more user-friendly ways to configure visibility. Plugins may also offer advanced options to toggle settings via custom user roles.

Setting visibility per user role

As the code examples demonstrate, functions can detect the current user’s role such as ‘subscriber’ to assign visibility rules accordingly. Expanding on role-based determination allows fine-grained control over which user levels see which editor options.

Automating visibility settings

Hardcoding visibility functions requires a developer to manually update files. For easier maintenance, solutions like the Meta Box Visibility plugin enable administrators to override defaults through the WordPress dashboard on a continual basis.

Summary

Setting intelligent restrictions on meta box visibility by default can greatly benefit the new user onboarding experience in WordPress. By minimizing complex options in the post editor, we allow new users to smoothly focus on creating content without unnecessary distraction or confusion. Functions inside theme files provide developers simple but powerful control over surfacing only essential post creation choices to guide users appropriately.

Administrators have additional options via plugins for easily extending default configurations as site needs evolve. Overall it is crucial to cautiously shape what users first encounter when authoring WordPress content, ensuring newcomers have the most accessible path towards effectively publishing their ideas online.

For further reading on modifying default meta boxes in WordPress, refer to:

Leave a Reply

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