I have a WordPress theme (the7) that includes the Visual Composer plugin. This is good for my clients editing stuff in the back end, but it also adds unnecessary CSS and JS to every page load on the front end. How can I remove these?
The lines it adds are:
<link rel="stylesheet" id='js_composer_front-css' href="https://wordpress.stackexchange.com/questions/255071/[domain]/wp-content/plugins/js_composer/assets/css/js_composer.min.css?ver=5.0.1" type="text/css" media="all" />
<script type="text/javascript" src="[domain]/wp-content/plugins/js_composer/assets/js/dist/js_composer_front.min.js?ver=5.0.1"></script>
I found this question which gives a possible method, but I can’t get it to work.
I tracked down where the specific CSS file is loaded from, it’s in a class Vc_Base in this function:
public function enqueueStyle() {
$post = get_post();
if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {
wp_enqueue_style( 'js_composer_front' );
}
wp_enqueue_style( 'js_composer_custom_css' );
}
So I set up this in my functions.php:
function inf_remove_junk()
{
wp_dequeue_style('js_composer_front');
wp_dequeue_style('js_composer_custom_css');
wp_dequeue_script('wpb_composer_front_js');
// also tried this
remove_action('wp_enqueue_scripts', array('Vc_Base', 'enqueueStyle'));
}
if (!is_admin()) {
add_action('wp_head', 'inf_remove_junk');
}
The inf_remove_junk
function definitely executes, but it doesn’t remove the CSS. Does it need to hook into a different point or do something else?