Created
July 2, 2015 14:58
-
-
Save bdeleasa/d59a0cda471893bdd1b0 to your computer and use it in GitHub Desktop.
Stops the Nextgen Gallery scripts from being loaded on pages without a gallery
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 | |
/** | |
* | |
* @wordpress-plugin | |
* Plugin Name: NextGen Gallery Script Optimizer | |
* Plugin URI: http://chooserethink.com | |
* Description: Removes NextGen Gallery scripts on pages that don't have a gallery on it. | |
* Version: 1.0.0 | |
* Author: Brianna Deleasa @ re:think | |
* Author URI: http://chooserethink.com | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Text Domain: ngg-script-optimizer | |
* Domain Path: /languages | |
*/ | |
// If this file is called directly, abort. | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
} | |
add_action( 'wp_enqueue_scripts', 'ngg_script_optimizer_remove_nextgen_gallery_scripts_styles', 99999); | |
/** | |
* Dequeues NextGen Gallery scripts that aren't needed. | |
* | |
* @param none | |
* @return none | |
* | |
* @since 1.0.0 | |
*/ | |
function ngg_script_optimizer_remove_nextgen_gallery_scripts_styles() { | |
global $post; | |
// Get out now if the current post has a gallery. | |
if ( strpos($post->post_content, 'ngg_displayed_gallery') !== false ) { | |
return; | |
} | |
$nextgen_gallery_scripts = array( | |
'ngg_lightbox_context', | |
'fancybox-0', | |
'fancybox-1', | |
'fancybox-2' | |
); | |
foreach($nextgen_gallery_scripts as $script) { | |
wp_dequeue_script($script); | |
} | |
$nextgen_gallery_styles = array( | |
'fancybox-0' | |
); | |
foreach($nextgen_gallery_styles as $style) { | |
wp_dequeue_style($style); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment