WordPress.org

Forums

Loading script only on homepage (3 posts)

  1. JCKnoell
    Member
    Posted 11 months ago #

    beta.cleantelligent.com

    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.

  2. 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.

  3. JCKnoell
    Member
    Posted 11 months ago #

    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. :)

Reply

You must log in to post.

About this Topic