removing unnecessary code?

Home Forums Easy FancyBox Pro removing unnecessary code?

This topic contains 1 reply, has 2 voices, and was last updated by  devin 2 years, 11 months ago.

  • Author
    Posts
  • #3383

    devin
    Participant

    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

  • #3384

    RavanH
    Keymaster

    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);
    

You must be logged in to reply to this topic.