I have been attempting to disable the ability to collapse admin meta boxes. By the looks of it WordPress creates this functionality in postbox.js /wp-admin/js/ but I have been unable to find a hook or suitable JavaScript to overwrite the built in functions.
This is a some test code I am working with:
jQuery('.postbox h3, .postbox .handlediv, .hndle').bind('click', function(e) {
e.preventDefault();
return false;
});
Any thoughts on how this could be achieved?
I have been attempting to disable the ability to collapse admin meta boxes. By the looks of it WordPress creates this functionality in postbox.js /wp-admin/js/ but I have been unable to find a hook or suitable JavaScript to overwrite the built in functions.
This is a some test code I am working with:
jQuery('.postbox h3, .postbox .handlediv, .hndle').bind('click', function(e) {
e.preventDefault();
return false;
});
Any thoughts on how this could be achieved?
Share Improve this question asked Oct 24, 2011 at 14:42 ScottScott 4219 silver badges16 bronze badges3 Answers
Reset to default 4Add this to your functions file and it will kill the metabox toggles:
function kill_postbox(){
global $wp_scripts;
$footer_scripts = $wp_scripts->in_footer;
foreach($footer_scripts as $key => $script){
if('postbox' === $script)
unset($wp_scripts->in_footer[$key]);
}
}
add_action('admin_footer', 'kill_postbox', 1);
For current Wordpress version (4.5.3) I come up with the following solution which removes closing metaboxes handler and opens all previously closed metaboxes.
php (plugin.php)
function add_admin_scripts( $hook ) {
wp_register_script( 'disable_metabox_toggling', plugin_dir_url(__FILE__) . 'index.js', 'jquery', '1.0.0', true);
wp_enqueue_script( 'disable_metabox_toggling' );
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 );
js (index.js)
(function($){
$(document).ready(function() {
$('.postbox .hndle').unbind('click.postboxes');
$('.postbox .handlediv').remove();
$('.postbox').removeClass('closed');
});
})(jQuery);
If you want to use it inside theme you should replace plugin_dir_url(__FILE__)
with get_template_directory_uri()
or get_stylesheet_directory_uri()
for a child theme.
Simplified & best version :
function disable_metabox_folding()
{ ?><script>
jQuery(window).load(function() {
jQuery('.postbox .hndle').css('pointer-events', 'none');
jQuery('.postbox .hndle').unbind('click.postboxes');
jQuery('.postbox .handlediv').remove();
jQuery('.postbox').removeClass('closed');
});
</script><?php
}
add_action('admin_footer', 'disable_metabox_folding');
//thanks to @jmarceli for hints