Disabling CMB2 styles on a whole site
March 17, 2015
Disabling CMB2 styles site wide with a filter solution.
The problem
I've been using (Custom Meta Boxes 2)[https://github.com/WebDevStudios/CMB2\] to quickly add meta boxes to pages and posts for a while and while I'm not that sensible to visual styles I can understand the styles CMB2 ships with might to be the best in any situation.
CMB2 provides an easy way to disable its styles on a per meta box base setting the meta box cmb2_styles
attribute to false
$meta_boxes['test_metabox'] = array(
'id' => 'test_metabox',
'title' => __( 'Test Metabox', 'cmb2' ),
'object_types' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
// 'cmb_styles' => false, // false to disable the CMB stylesheet
// 'closed' => true, // Keep the metabox closed by default
'fields' => array(
...
but that's a distributed solution that's not easy to turn on and off for a whole site.
A filter solution
The way I've solved the issue is using a simple must use plugin that will dequeue CMB2 styles no matter what the setting on the single meta boxes is.
<?php
/*
Plugin Name: CMB2 site-wide style killer
Description: Disables CMB2 styles in the whole site no matter the single meta boxes setting.
Author: Luca Tumedei
Author URI: http://theaveragedev.local
Version: 1.0
*/
add_action( 'admin_enqueue_scripts', function () {
wp_dequeue_style( 'cmb2-styles' );
}, 999 );
This will work used as a normal plugin too.