Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i have customized my .html as a custom wp theme. i have these scripts in my header.php:

<script type='text/javascript' src="scripts/jquery-1.8.2.js"></script>
<script type='text/javascript' src='scripts/jquery.easing.1.3.js'></script>
<script type='text/javascript' src='scripts/jquery.hoverIntent.minified.js'></script> 
<script type='text/javascript' src='scripts/diapo.js'></script>
<script type="text/javascript" src="scripts/scripts.js"></script>

<!--[if !IE]><!--><script type='text/javascript' src='scripts/jquery.mobile-1.0rc2.customized.min.js'></script><!--<![endif]-->

<!-- html5.js for IE less than 9 -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

I am really new in all these wp customization stuff and i am struggling through dozens of tutorials by great minds out there sharing their knowledge. after a quite long search before posting here, i see that the right way including these files is registering and queuing them inside my functions.php file.

so, my "functions.php" has this:

function load_javascript_files() {

//Register the script like this for a theme:
wp_register_script('easing', get_template_directory_uri() . 'http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js', array('jquery'), '1.3', true);
wp_register_script('hoverIntent', get_template_directory_uri() . '/js/jquery.hoverIntent.minified.js', array('jquery'), true);
wp_register_script('jquery-mob-custom', get_template_directory_uri() . '/js/jquery.mobile-1.0rc2.customized.min.js', array(jquery), true);
wp_register_script('home-page-slideshow', get_template_directory_uri() . '/js/diapo.js', array('jquery'), true);
wp_register_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), '1.0', true);


wp_enqueue_script('easing');
wp_enqueue_script('hoverIntent');
wp_enqueue_script('custom-script');

global $is_IE;

if ( $is_IE ) {
wp_enqueue_script('jquery-mob-custom');
}

if(is_front_page()) {
    wp_enqueue_script('home-page-slideshow');
}
}
add_action('wp_enqueue_scripts', 'load_javascript_files');

?>

Any help of understanding what i am doing wrong here is really appreciated

share|improve this question
    
in your easing script, you append get_template_directory_uri() to an absolute URL. –  Milo Mar 14 '13 at 1:26
    
What does the rendered output (browser source) show? Are any of the scripts enqueued, or are none of the scripts enqueued? –  Chip Bennett Mar 14 '13 at 1:34
add comment

2 Answers

Probable Cause

I strongly suspect that you do not call wp_head() in your header.php file, immediately before the closing HTML </head> tag:

<?php wp_head(); ?>
</head>

You must call this template tag, in order to fire the wp_head action. The wp_head action in turn fires the wp_enqueue_scripts action. So, without having <?php wp_head(); ?> in your template, you won't fire wp_enqueue_scripts.

Syntax Errors

You have at least three syntax errors:

  1. Concatenated script URL:

    wp_register_script('easing', get_template_directory_uri() . 'http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js', array('jquery'), '1.3', true);
    

    This:

    get_template_directory_uri() . 'http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js'
    

    ...should be this:

    get_template_directory_uri() . '/js/easing/jquery.easing.1.3.js'
    
  2. Array key string:

    wp_register_script('jquery-mob-custom', get_template_directory_uri() . '/js/jquery.mobile-1.0rc2.customized.min.js', array(jquery), true);
    

    This:

    array(jquery)
    

    ...should be this:

    array( 'jquery' )
    
  3. Incorrect wp_enqueue_script() parameter ordering

    wp_register_script('hoverIntent', get_template_directory_uri() . '/js/jquery.hoverIntent.minified.js', array('jquery'), true);
    wp_register_script('jquery-mob-custom', get_template_directory_uri() . '/js/jquery.mobile-1.0rc2.customized.min.js', array(jquery), true);
    wp_register_script('home-page-slideshow', get_template_directory_uri() . '/js/diapo.js', array('jquery'), true);
    

    In each case, you need to add the $version parameter between $deps and $footer

share|improve this answer
    
about 1 and 2 are indeed totally false but scripts don't work either way. about the 1st probably this confused me: wordpress.org/support/topic/… –  heyJim Mar 14 '13 at 8:18
    
about the $version i thought that it is optional. if not, then what should i write for $version? by including <script type='text/javascript' src='<?php bloginfo('template_url'); ?>/js/jquery.easing.1.3.js'></script> instead of the wp_register and wp_enqueue is not the right way? viewing code source, my scripts do not appear anywhere in the <head>.. –  heyJim Mar 14 '13 at 8:47
add comment

Problem solved, but to be honest, i did not totally comprehend why was this happening: i did not register my scripts, just used wp_enqueue_script(); inside my function and now everything is working fine. Simply deleted the wp_register_script(); as it seems that it messed things up. Thank you, however.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.