Created
November 21, 2013 19:12
-
-
Save DevinWalker/7587729 to your computer and use it in GitHub Desktop.
Load LayerSlider scripts/styles only when a shortcode is present in the content (can be modified to custom meta, etc).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Load LayerSlider Scripts only when shortcode is present | |
* | |
* Deregister Scripts from LayerSlider if no shortcode in content | |
* Using do_shortcode function? See: http://wordpress.stackexchange.com/questions/20854/conditionally-loading-javascript-css-for-shortcodes/75915#75915 | |
*/ | |
function check_for_layerslider_shortcode() { | |
global $post; | |
//Check content for layerslider shortcode | |
if (!has_shortcode($post->post_content, 'layerslider')) { | |
//no shortcode so run deenqueue function | |
add_action('wp_print_scripts', 'layerslider_deenqueue_scripts', 99999); | |
add_action('wp_print_styles', 'layerslider_deenqueue_scripts', 99999); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'check_for_layerslider_shortcode'); | |
/** | |
* Removes LayerSlider scripts | |
*/ | |
function layerslider_deenqueue_scripts() { | |
wp_dequeue_script('layerslider_js'); | |
wp_deregister_script('layerslider_js'); | |
wp_dequeue_script('jquery_easing'); | |
wp_deregister_script('jquery_easing'); | |
wp_dequeue_script('transit'); | |
wp_deregister_script('transit'); | |
wp_dequeue_script('layerslider_transitions'); | |
wp_deregister_script('layerslider_transitions'); | |
wp_dequeue_style('layerslider_css'); | |
wp_deregister_style('layerslider_css'); | |
wp_dequeue_style('layerslider_custom_transitions'); | |
wp_deregister_style('layerslider_custom_transitions'); | |
wp_dequeue_style('layerslider_custom_css'); | |
wp_deregister_style('layerslider_custom_css'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment