You need to use action wp_enqueue_scripts
except wp_head
like:
function inf_remove_junk() {
if (!is_admin()) {
wp_dequeue_style('js_composer_front');
wp_dequeue_style('js_composer_custom_css');
wp_dequeue_script('wpb_composer_front_js');
}
}
add_action( 'wp_enqueue_scripts', 'inf_remove_junk' );
But it remove the scripts from front end.
-
I think on archive pages VC does not execute it’s shortcode. So you can check is_archive() condition instead of is_admin().
-
Or you can check the shortcode from content and remove assets like:
function inf_remove_junk() {
// 1. Check shortcode exist in post content and disable scripts. global $post; if ( stripos($post->post_content, '[YOUR_SHORTCODE]') ) { // or // 2. Disable scripts on all pages except single page, post, custom Post etc. if ( ! singular() ) { // or // 3. Disable on archive, 404 and search page if ( is_archive() || is_404() || is_search() ) { wp_dequeue_style('js_composer_front'); wp_dequeue_style('js_composer_custom_css'); wp_dequeue_script('wpb_composer_front_js'); }
}
add_action( ‘wp_enqueue_scripts’, ‘inf_remove_junk’ );
Also, For premium plugin support you need to contact plugin author for better answer.