• Resolved Russ

    (@gfxdesigner)


    I would like to use this plugin on a gallery page, but in terms of overhead, I would like to not have this plugin loaded on all other pages.

    My plan would be to disable this plugins functions from my theme’s functions.php and then create a separate template file for my gallery page that would then load the plugins functions.

    Would it be possible to provide the functions for both files?

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Russ,

    You could try adding something like https://wordpress.org/support/topic/disable-fancybox-for-homepage/ to your theme’s functions.php … but use an opposite conditional like if ( is_page('gallery') ) (assuming your gallery page has the page slug ‘gallery’)

    Thread Starter Russ

    (@gfxdesigner)

    Thank you for pointing me in that direction. I have it working with that logic.

    // Disable FancyBox on all pages
    {
    remove_action(‘wp_enqueue_scripts’, array(‘easyFancyBox’, ‘enqueue_styles’), 999);
    remove_action(‘wp_head’, array(‘easyFancyBox’, ‘main_script’), 999);
    remove_action(‘wp_print_scripts’, array(‘easyFancyBox’, ‘register_scripts’), 999);
    remove_action(‘wp_footer’, array(‘easyFancyBox’, ‘enqueue_footer_scripts’));
    remove_action(‘wp_footer’, array(‘easyFancyBox’, ‘on_ready’), 999);
    }

    // Enable FancyBox only on Gallery page
    add_action(‘wp_head’,’my_conditional_script’,0);

    function my_conditional_script() {
    if ( is_page(‘Gallery’) ) {
    add_action(‘wp_enqueue_scripts’, array(‘easyFancyBox’, ‘enqueue_styles’), 999);
    add_action(‘wp_head’, array(‘easyFancyBox’, ‘main_script’), 999);
    add_action(‘wp_print_scripts’, array(‘easyFancyBox’, ‘register_scripts’), 999);
    add_action(‘wp_footer’, array(‘easyFancyBox’, ‘enqueue_footer_scripts’));
    add_action(‘wp_footer’, array(‘easyFancyBox’, ‘on_ready’), 999);
    }
    }

    If you feel that there would be a more appropriate or elegant approach, then please feel free to let me know.

    Thank you.

    Excellent work. Your code removes the script files and only on Gallery adds them again.

    Shorter would be to remove them using an “is not” conditional:

    
    add_action(‘wp_head’,’my_conditional_script’,0);
    
    function my_conditional_script() {
      if ( ! is_page(‘Gallery’) ) {
        remove_action(‘wp_enqueue_scripts’, array(‘easyFancyBox’, ‘enqueue_styles’), 999);
        remove_action(‘wp_head’, array(‘easyFancyBox’, ‘main_script’), 999);
        remove_action(‘wp_print_scripts’, array(‘easyFancyBox’, ‘register_scripts’), 999);
        remove_action(‘wp_footer’, array(‘easyFancyBox’, ‘enqueue_footer_scripts’));
        remove_action(‘wp_footer’, array(‘easyFancyBox’, ‘on_ready’), 999);
      }
    }
    

    (Note the exclamation mark before is_page, it means “not”)

    Advantage is that you do not need to add them again because this will remove the files everywhere except Gallery.

    Hope that helps 🙂

    Thread Starter Russ

    (@gfxdesigner)

    Thank you for the more elegant approach!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disable on all but one page’ is closed to new replies.