Disable dragging of meta boxes?

I had the same problem, and Google lead me here. Unfortunately none of these answers helped, but I ultimately figured out the answer, and it’s quite easy!

  1. First, enqueue a JavaScript file (I won’t rehash this process; there are many tutorials that can describe this process better than I). I hooked into admin_enqueue_scripts, and it worked fine.
  2. Disable the sorting functionality by putting this in that JavaScript file:

    jQuery(document).ready( function($) {
        $('.meta-box-sortables').sortable({
            disabled: true
        });
    
        $('.postbox .hndle').css('cursor', 'pointer');
    });
    

Essentially this just disables jQuery UI Sortable, which powers the metabox dragging functionality (postbox.dev.js:64). This also switches the cursor on the metabox handle to a standard mouse pointer instead of a move cursor (idea courtesy of brasofilo below).

Hope this helps!

Edit: I should add that it’s probably worth following some of the other advice here and disabling the saving of the metabox order. It will prevent confusion on the off-chance something gets mistakenly re-enabled.

Second edit: For the benefit of future generations (and future Google searchers), this fix was tested on WordPress 3.3.1. I can’t speak to other versions!

Leave a Comment