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.

This question already has an answer here:

I have multiple JavaScript files that I want to load. Some of them in my header.php and the rest in the footer.php.

These are the files:

<?php
<script type="text/javascript src="/scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript src="/scripts/contact.js"></script>
<script type="text/javascript src="/scripts/jquery.easing.1.3.js"></script>
<script src="scripts/jsCarousel-2.0.0.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
    $('#carouselv').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: false, itemstodisplay: 3, orientation: 'v' });
        $('#carouselh').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, circular: true, masked: false, itemstodisplay: 3, orientation: 'h' });
        $('#carouselhAuto').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: true, itemstodisplay: 5, orientation: 'h' });

    });               
</script> ?>
share|improve this question
    
Any of these qustions/answers should also help. –  Chip Bennett Feb 6 '13 at 13:17
add comment

marked as duplicate by Chip Bennett, brasofilo, kaiser, s_ha_dum, toscho Feb 6 '13 at 17:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 0 down vote accepted

You can't have <script> elements within your PHP like that. Either take them out of the PHP delimiters (<?php ?>) or use wp_register_script() and wp_enqueue_script() to get your scripts within WordPress.

Update

how can i use wp_enqueue_script() with multiple scripts ?

wp_register_script( 'jquery-1.8.2', get_template_directory_uri() . '/scripts/jquery-1.8.2.min.js' );
wp_register_script( 'contact', get_template_directory_uri() . '/scripts/contact.js' );
wp_register_script( 'easing-1.3', get_template_directory_uri() . '/scripts/jquery.easing.1.3.js' );
wp_register_script( 'carousel-2.0.0', get_template_directory_uri() . '/scripts/jsCarousel-2.0.0.js' );
wp_register_script( 'starter', get_template_directory_uri() . '/scripts/starter.js' );

wp_enqueue_script( 'jquery-1.8.2' );
wp_enqueue_script( 'contact' );
wp_enqueue_script( 'easing-1.3' );
wp_enqueue_script( 'carousel-2.0.0' );
wp_enqueue_script( 'starter' );

Then in the starter.js script you can put:

$(document).ready(function() {
    $('#carouselv').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: false, itemstodisplay: 3, orientation: 'v' });
    $('#carouselh').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, circular: true, masked: false, itemstodisplay: 3, orientation: 'h' });
    $('#carouselhAuto').jsCarousel({ onthumbnailclick: function(src) { alert(src); }, autoscroll: true, masked: true, itemstodisplay: 5, orientation: 'h' });
});
share|improve this answer
    
thanks for replay but i removed the files from the php but its not working –  sarah Feb 6 '13 at 13:04
    
Are you sure the paths are correct? I see you use src="/scripts/ and then later on src="scripts/. –  stealthyninja Feb 6 '13 at 13:35
    
how can i use wp_enqueue_script() with multiple scripts ? –  sarah Feb 8 '13 at 21:16
add comment

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