How to Disable Dragging of Metaboxes Within WordPress Admin

Home » Snippets » How to Disable Dragging of Metaboxes Within WordPress Admin

Created with:



Creator: WPTurbo Team

Customize with WPTurbo AI

Add Snippet To Project

New Project
Add To Existing Project

If you’re an avid WordPress user, you know that the dashboard can quickly become cluttered with metaboxes. While the draggable feature allows you to rearrange these boxes to your liking, it can also be a frustrating experience when you accidentally drag a box out of place or can’t seem to get it to settle where you want it. In this article, we’ll show you how to disable the metabox drag feature in the WordPress admin to make your dashboard experience smoother and more streamlined.

					function wpturbo_disable_metabox_dragging() {
    wp_deregister_script( 'postbox' );
add_action( 'admin_enqueue_scripts', 'wpturbo_disable_metabox_dragging' );

The code snippet above shows a way to disable the dragging of metaboxes within the WordPress admin dashboard. This can be helpful if you want to lock down the layout of the dashboard and prevent users from accidentally moving the metaboxes around.

The function wpturbo_disable_metabox_dragging() is where most of the magic happens. This function is hooked into the admin_enqueue_scripts action, which means that it will be executed when the scripts for the admin dashboard are being loaded.

The function itself is calling wp_deregister_script( 'postbox' ). This function will deregister the original WordPress script responsible for handling the dragging of metaboxes within the dashboard. By deregistering this script, we prevent the user from dragging any of the metaboxes around.

Note that while this approach prevents users from dragging metaboxes around, it doesn’t completely remove them. Users will still be able to collapse or expand the metaboxes by clicking on the appropriate arrows or buttons, but they won’t be able to move them around within the dashboard anymore.

Overall, this code snippet is a simple but effective way of locking down the dashboard layout in WordPress and preventing accidental mistakes when using the admin panel.

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