Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi, try this:

    
    add_action( 'wp_enqueue_scripts', 'my_conditional_fancybox', 0 );
    
    function my_conditional_fancybox() {
        if ( is_home() || is_front_page() ) {
            if ( class_exists('easyFancyBox') ) easyFancyBox::$add_scripts;
        }
    }
    
    Thread Starter dg

    (@denizgezgin)

    Thank you for the answer, but it does not seem to work. All scripts and styles related to the plugin are still loading on every page. Should I dequeue everything first and then conditionally load them as you suggested?

    My apologies, I left something essential out of that code snippet: the = false to actually do the removal of the scripts… The code example should have been:

    
    add_action( 'wp_enqueue_scripts', 'my_conditional_fancybox', 0 );
    
    function my_conditional_fancybox() {
        if ( is_home() || is_front_page() ) {
            if ( class_exists('easyFancyBox') )
                easyFancyBox::$add_scripts = false;
        }
    }
    
    Thread Starter dg

    (@denizgezgin)

    Perfect! Thanks

    Hello,

    How does the code look to disable on more than one page? eg.

    domain.com / news-updates / news-page-1
    domain.com / about-us
    etc.

    thanks

    Hi @lilbunny it’s in the if() statement. In the example there is is_home() || is_front_page() in theren which means “if the page is home or front page”. Change that to something like is_page('news-page-1') || is_page('about-us') using the slug to identify the pages. Instead of the slug, you can use the ID or even the Title (must be an exact match) and if you have a long list of pages you can use an array, like for example:

    
    if ( is_page( array(15,29,300,301,9) ) ) {
    

    (using ID’s to identify the pages)

    Thank you for showing me that, that’s really cool.

    It doesn’t seem to be working on posts though. When we add page IDs it disables, but if we add a post ID or custom post type ID FancyBox isn’t disabling.

    Can FancyBox be disabled on posts?

    To clarify, can it be disabled on BOTH, posts and pages?
    e.g. Post ID 20, Page ID 21

    Yes, for posts (and custom post types) you need to use is_single() the same way as is_page(). So your IF statement might look like:

    
    if ( is_page( array(15,29) ) || is_single( array(300,301,9) ) ) {
    

    Thank you, that works great!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Load plugin only on certain page(s)’ is closed to new replies.