removing unnecessary code?
- This topic has 1 reply, 2 voices, and was last updated 12 years, 6 months ago by .
- You must be logged in to reply to this topic.
Your Account / Forums / Easy FancyBox Pro / removing unnecessary code?
Hello,
I just purchased Easy FancyBox Pro, and it is working well. I noticed that the plugin is loading a bunch of js and css code on every page of my site:
<!-- Easy FancyBox 1.5.6 using FancyBox 1.3.6 - RavanH (http://status301.net/wordpress-plugins/easy-fancybox/) -->
<script type="text/javascript">
/* <![CDATA[ */
var fb_timeout = null;
etc...
Is there an easy way to only include this code on pages where the fancybox plugin is being used? I am only using FancyBox features on one page.
Thanks,
Devin
Hi Devin,
The plugin itself can not detect if the code is going to be needed or not so that is why it is included in every page. That said, you can manually add the following code to your themes functions.php file. I’m supposing here that the page in question has slug ‘portfolio’ used in !is_page('portfolio') but you can change that to fit your case 🙂
function my_conditional_script() {
if( class_exists('easyFancyBox') && !is_page('portfolio') ) {
remove_action('wp_enqueue_scripts', array('easyFancyBox','enqueue_styles'), 999);
remove_action('wp_print_scripts', array('easyFancyBox','register_scripts'), 999);
remove_action('wp_head', array('easyFancyBox','main_script', 999);
remove_action('wp_footer', array('easyFancyBox','enqueue_footer_scripts'), 999);
remove_action('wp_footer', array('easyFancyBox', 'on_ready'), 999);
}
}
add_action('wp_head','my_conditional_scripts',0);