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

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)