Drupal JavaScript snippet - Reset block placement to "None"

When you change themes on a Drupal 7 site, you often need to reset the placement of your blocks. If you're using the core block module to place them, you may end up with a bunch of blocks in unexpected places on your new theme. If you want to reset everything and start from scratch, you could edit the {blocks} table in your database, but you can also do it with JavaScript. While viewing the blocks admin page (admin/structure/blocks), paste this line into your JavaScript console:

jQuery('#blocks').find('select').val(-1);

That will reset every block's region to "- None -", without saving the page. If you want to get a little crazier, you can use this line to reset the blocks and save your changes in one action:

jQuery('#blocks').find('select').val(-1); jQuery('#block-admin-display-form').submit();

These could be placed in a bookmarklet, dragged into your browser's bookmark menu or toolbar, accessible with a click. Get the bookmarklet version of these snippets here (Drupal rightly strips out embedded JavaScript, so I created a static file for this). This bookmarklet could be enhanced to make sure you're on the right page before trying to do anything, but I'll leave as an exercise for the reader (either to do it, or to bug me to do it!).

Comments

Matthew Wrather

Great tip, Joe. I find that I'm using the JS console almost more like a CLI for web pages than as a development tool these days.

Joe Chellman

Hey Matt,

Yeah, using the JS console that way is really handy. Knowing a little bit about a web inspector is something that could be useful for anyone, web developer or not.

Comments are closed on this post to keep spammers at bay. If you want to chime in, please email or send a tweet.