How to Remove the Post Revisions Metabox in WordPress

Home » Snippets » How to Remove the Post Revisions Metabox in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Is your WordPress dashboard cluttered with post revisions that you no longer need? Or, perhaps you simply want to clean up your workflow to only focus on necessary elements. If that’s the case, removing the post revisions metabox can be a beneficial move. In this article, we’ll guide you through the steps to safely and effectively remove the post revisions metabox from your WordPress dashboard, making your editing experience sleek and streamlined.

					function wpturbo_remove_post_revisions_metabox() {
    remove_meta_box('revisionsdiv', 'post', 'normal');
}
add_action('admin_menu', 'wpturbo_remove_post_revisions_metabox');
				

Our snippet begins with declaring a new function called wpturbo_remove_post_revisions_metabox(). This function is designed to remove the post revisions meta box that is displayed in WordPress by default.

function wpturbo_remove_post_revisions_metabox() {
    remove_meta_box('revisionsdiv', 'post', 'normal');
}

The function utilizes the WordPress function called remove_meta_box(). The remove_meta_box() function, as the name suggests, removes a meta box from one or more screens.

The remove_meta_box() function takes three parameters:

  1. Id (String): The ID of the meta box to remove. This ID is used in the HTML ‘id’ attribute.
  2. Screen (string|WP_Screen|array): The screen or screens on which the meta box is shown (such as ‘post’ or ‘page’). It can also be a WP screen object or an array of $screen-ids.
  3. Context (string): The context within the screen where the boxes should display. Contexts include ‘normal’, ‘side’, and ‘advanced’.

In our code snippet, the ID of the meta box we want to remove is ‘revisionsdiv’, and we are choosing to remove it from the ‘post’ which is the default post screen in WordPress. The context for the meta box is ‘normal’.

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

The next line of our code is crucial because it attaches our newly formed function (wpturbo_remove_post_revisions_metabox()) to a WordPress action hook called admin_menu.

add_action('admin_menu', 'wpturbo_remove_post_revisions_metabox');

This add_action() function hooks our wpturbo_remove_post_revisions_metabox() function into WordPress, making sure that it gets fired at the correct time when WordPress is building the admin menu. This means that the post revisions meta box is removed right before the user views the post editing screen. The way we’ve structured this, our function will only run in the admin section of WordPress, as that’s where the ‘admin_menu’ hook is triggered, ensuring that we’re not loading unnecessary code on the front-end of the site.

Register an account to save your snippets or go Pro to get more features.