Skip to content

Instantly share code, notes, and snippets.

@shrwnsan
Created May 7, 2013 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrwnsan/5532340 to your computer and use it in GitHub Desktop.
Save shrwnsan/5532340 to your computer and use it in GitHub Desktop.
WordPress: Selectively load plugins' styles/JS only for pages/views that needs them
function my_deregister_styles() {
if (!is_page('Contact')) {
wp_deregister_style('contact-form-7');
}
if (!is_single()) {
wp_deregister_style('tfg_style');
}
}
function my_deregister_javascript() {
if (!is_page('Contact')) {
wp_deregister_script('contact-form-7');
}
if (!is_single()) {
wp_deregister_script('tfg_script');
}
}
add_action('wp_print_styles', 'my_deregister_styles', 100);
add_action('wp_print_scripts', 'my_deregister_javascript', 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment