Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ataylorme/4101193 to your computer and use it in GitHub Desktop.
Save ataylorme/4101193 to your computer and use it in GitHub Desktop.
Remove all enqueue'd scripts and styles for a custom post type
/* ========== START REMOVE ALL ENQUEUED EXISTING SCRIPTS AND STYLEs ========== */
if( !function_exists('clean_wp_head') ):
function clean_wp_head(){
if( !function_exists('MY_CUSTOM_POST_TYPE_remove_all_scripts') ):
function MY_CUSTOM_POST_TYPE_remove_all_scripts() {
global $wp_scripts; $wp_scripts->queue = array();
}//end MY_CUSTOM_POST_TYPE_remove_all_scripts function
endif;
if( !function_exists('MY_CUSTOM_POST_TYPE_remove_all_styles') AND !is_admin() ):
function MY_CUSTOM_POST_TYPE_remove_all_styles() {
global $wp_styles; $wp_styles->queue = array();
}//end MY_CUSTOM_POST_TYPE_remove_all_scripts function
endif;
if ( get_post_type() == 'MY_CUSTOM_POST_TYPE' AND !is_admin() ):
add_action('wp_print_scripts', 'MY_CUSTOM_POST_TYPE_remove_all_scripts', 100);
add_action('wp_print_styles', 'MY_CUSTOM_POST_TYPE_remove_all_styles', 100);
endif;
}//end clean_wp_head function
endif;
add_action('wp_head', 'clean_wp_head', 1);
/* ========== END REMOVE ALL ENQUEUED EXISTING SCRIPTS AND STYLEs ========== */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment