• Hi Everybody,

    I want to load jQuery in a good way. My problem is that jquery is on my page but it looks like i can’t use it.
    I use that function in my functions.php (in my theme):

    function init_jquery() {
    	if (!is_admin()) {
    		wp_enqueue_script('jquery');
    	}
    }
    add_action('init', 'init_jquery');

    I don’t have any plugin. My header.php looks like that:

    <?php
    	/* We add some JavaScript to pages with the comment form
    	 * to support sites with threaded comments (when in use).
    	 */
    	if ( is_singular() && get_option( 'thread_comments' ) )
    		wp_enqueue_script( 'comment-reply' );
    
    	/* Always have wp_head() just before the closing </head>
    	 * tag of your theme, or you will break many plugins, which
    	 * generally use this hook to add elements to <head> such
    	 * as styles, scripts, and meta tags.
    	 */
    	wp_head();
    ?>
    
    <script type="text/javascript" src="<?php bloginfo( 'template_directory' );?>/js/bgstretcher.js"></script>
    
    <script type="text/javascript" src="<?php bloginfo( 'template_directory' );?>/js/background.js"></script>

    I can see that jQuery is loaded: wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>

    But my script doesn’t work and then if I add <script type="text/javascript" src="<?php bloginfo( 'template_directory' );?>/js/jquery-1.4.2.min.js"></script>
    the script will work but that mean i don’t need to use function init_jquery() to load it!

    How i should load jQuery with TwentyTen?

    Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • try this once

    <?php
    	/* We add some JavaScript to pages with the comment form
    	 * to support sites with threaded comments (when in use).
    	 */
    	if ( is_singular() && get_option( 'thread_comments' ) )
    		wp_enqueue_script( 'comment-reply' );
    
    	/* Always have wp_head() just before the closing </head>
    	 * tag of your theme, or you will break many plugins, which
    	 * generally use this hook to add elements to <head> such
    	 * as styles, scripts, and meta tags.
    	 */
    
            wp_enqueue_script('jquery');
    
    	wp_head();
    ?>
    Thread Starter designrf

    (@designrf)

    Thanks but it doesn’t work ??

    Thread Starter designrf

    (@designrf)

    It looks like i found my problem.
    I forgot the $ in the function($)

    jQuery(document).ready(function($){
    //script here
    });

    have jquery-1.4.2.min.js file in your theme’s js folder?

    Thread Starter designrf

    (@designrf)

    Well it was just to try with different library if the issue was from the library version.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Jquery Load Problem’ is closed to new replies.