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 some trouble with loading external javascript files inside my WordPress theme. Use the following markup:

<script src="<?php bloginfo('template_directory'); ?>/js/jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/custom.js" type="text/javascript"></script>

The above code is set inside the <head> of my header.php file of my WordPress theme.

Why is this not working? Or should I also use the following for link external scripts?

function my_scripts() {
    wp_enqueue_script( 'my-sweet-script', get_bloginfo('template_directory') . '/script.js', array('jquery') );
}

Thank you. Casper

share|improve this question

1 Answer 1

You should always use wp_enqueue_script() only, so other scripts can rely on yours or bundle all scripts in one file.

Do not load another jQuery; WordPress comes with a built-in jQuery, and other plugins and the core depend on exactly that version.

wp_enqueue_script() accepts any valid URL as source file, external or internal. If something doesn't work check your browser's error console. Note you have to use jQuery, not $ in your scripts to access the global jQuery object.

share|improve this answer

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.