What’s the correct way to include files in WordPress TwentyTen theme with it’s own jquery scripts and css?

I want to include a slider in the default WordPress theme on the home page. I did manage to get the page to show using <?php if ( is_home() ) { include ('slider.php'); } ?> but it doesn’t look like it’s loading the jquery script it needs or the style sheet. I know there’s a conflict with scripts and WordPress, I just don’t know how to get it to work.

Sample page is at http://axiomwest.com/

Read More

How do you feed in a page with it’s own style sheet and scripts?

Related posts

Leave a Reply

2 comments

  1. You need to have the script in a separate file (normally it would be filename.js; I suppose filename.php would work?).

    Then, you need to register and enqueue that script file, using wp_register_script() and wp_enqueue_script()

    e.g.:

    function mytheme_register_custom_scripts() {
        if ( ! is_admin() ) {
            $scriptsrc = get_stylesheet_directory_uri() . '/scripts/filename.js';
            wp_register_script( 'mytheme_slider', $scriptsrc );
        }
    }
    add_action( 'after_setup_theme', 'mytheme_register_custom_scripts' );
    
    function mytheme_enqueue_custom_scripts() {
        if ( is_home() ) {
            wp_enqueue_script( 'mytheme_slider' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_custom_scripts' );
    

    Note that registering the script should happen at after_setup_theme, but is_home() will not be available at this point I don’t think, which is why you need to separate the enqueueing function so that it hooks into wp_head, by which time is_home() is available.

  2. UPDATE! What I did was just include the slider I was trying to use. I linked the jquery scripts that page needs via the <?php bloginfo('template_directory'); ?> method. I did notice that it takes a couple of seconds to load that portion of the page, but it works. I still think this can be improved, but with time constraints it will have to do. Thanks all for your comments and eagerness to help!