• Hi WP forums,

    I’m pretty much a beginner developer and am having some issues getting jquery (and other js) to run through the functions.php theme file.

    <?php
    function load_scripts() {
    	  wp_enqueue_script( 'jquery' );
    }
    add_action('init', 'load_scripts');
    ?>

    That the only bit of code within my functions.php. When I use the chrome developer console, I can see that jquery is not loading. Am I missing a step?

    Many thanks in advance for any help I can get.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter vehemoth

    (@phunz)

    Ok, I’ve tried everything I can possibly think of – nothing is working except adding the scripts into the footer via html:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"><script src="../js/script.js?v=2"></script>

    functions.php is firing, but the wp_enqueue_script seems to be failing, so I’ve tried placing into footer.php like so:

    <?php 
    
    		wp_register_script('custom_script', get_bloginfo('template_directory') . '/js/script.js', array('jquery') );
    
    		wp_enqueue_script('custom_script');
    
    	?>

    ..to no avail.

    In functions.php, also not working:

    <?php
    
    function load_scripts() {
    
    	if ( !is_admin() ) {  
    
    		wp_register_script('custom_script', get_bloginfo('template_directory') . '/js/script.js', array('jquery') );
    
    		wp_enqueue_script('custom_script');
    
    	}
    
    }
    
    add_action('init', 'load_scripts');
    
    ?>

    I can’t imagine it’s a bug or something. I assume I’ve missed a step, and cannot find a solution, can anyone help?

    Thanks,

    does your theme include the required calls to wp_head and wp_footer?

    Thread Starter vehemoth

    (@phunz)

    Thank for your speedy reply, Matt.

    My theme has

    <?php get_header(); ?> 
    
    /*html*/
    
    <?php get_footer(); ?>

    it is also a custom page, could this be an issue?

    Open up header.php and footer.php and look for wp_head(); and wp_footer();

    Thread Starter vehemoth

    (@phunz)

    Ah, I just learned so much from that bit of info. Problem solved, thanks heaps Matt!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problems with wp_enqueue_script in functions.php’ is closed to new replies.