• Resolved Will White

    (@willpcg)


    I’ve started setting up a new site for our office, and its coming along great. On the home page I use 2 jQuery image sliders that work great. One of the two sliders is carried out as part of the header throughout the site – while the other is only used on the home page.

    I’ve found that because the 2nd slider isn’t present on the interior pages, but the javascript file that supports it is still called in the header area of the page, its creating an error that stops the header slider from working.

    Is there a way to have certain javascript files only load on the home page and not the interior pages?

    The pages I’m referencing are:
    https://www.pinpointcreative.com/revision
    https://www.pinpointcreative.com/revision/about

    Thanks for any advice, or even just some direction towards where I should be looking for answers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Jonas Grumby

    (@ss_minnow)

    You need to use Conditional Tags.

    Thread Starter Will White

    (@willpcg)

    is_front_page() is exactly what I need.

    Thanks SS_Minnow! I didn’t think it would be that easy.

    Jonas Grumby

    (@ss_minnow)

    No problem. Often it makes your code cleaner to put the javascript in an external file in your theme folder and then write something like

    <?php if ( is_front_page() ) { ?>
    <?php include(TEMPLATEPATH.'/myscript.js');?>
    <?php } else { ?>
    <?php     // This page does not get the javascript
    }
    ?>

    Of course myscript.js should be changed to the name of the file that contains your script.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Omitting JS files in Interior Pages’ is closed to new replies.