Support » Themes and Templates » Loading script only on homepage


    Okay, so I’ve been trying to use wp_enqueue_script for weeks and I still can’t seem to figure it out.

    I finally figured out what’s wrong with my web site. There are two scripts on my homepage which are screwing up the plugins on my other pages. If I could get those scripts to load ONLY on the home page, then they wouldn’t mess with my other page’s plugins.

    Can anyone please help me with this? I don’t even know WHERE to put wp_enqueue_script, let alone why it isn’t working… I’ve read the function reference page a dozen times and it’s assuming I know things I don’t…

    Please, any help would be wonderful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Christine Rondeau


    Volunteer Forum Moderator

    I often do this with sliders on the home page.

    I use something like this in my theme:

    if ( is_front_page() ) {
    		wp_enqueue_script( 'slides', get_template_directory_uri().'/js/jquery.flexslider-min.js', array( 'jquery' ) );

    I do this inside a function.

    In order to familiarize yourself with this code, I would recommend looking at twentytwelve or one of the other twenties. These themes are a great place to learn.

    So, is this located inside of functions.php?

    It seems every time I try to add something to my functions.php (Yes, I’m using a child) it breaks my website… Is there anywhere else I can put this?

    Also, what parts of that code do I need to customize? obviously the information inside the wp_enqueue_script() brackets needs to be for my scripts. Is everything else the way it should be? (I don’t know php or javascript very well… haha)

    What is get_template_directory, for example?

    Also, can I do this twice? once for each script that is on my home page?

    Thank you so much for your help. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loading script only on homepage’ is closed to new replies.