WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a ticker jQuery plugin and having trouble loading my script files correctly. If I add the scripts in directly into the theme's header.php file my scripts work correctly.

<script src="<?php bloginfo('template_directory'); ?>/js/jquery-ticker.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/site.js"></script>

If I try to load the scripts from a WordPress plugin I receive an error. Plugin code:

function bbc_frontend_script() {
wp_enqueue_script('ticker', plugins_url("/js/jquery-ticker.js", __FILE__));
wp_enqueue_script('js', plugins_url("/js/site.js", __FILE__));
add_action( 'wp_enqueue_scripts', 'bbc_frontend_script' );

The error I receive is the console outputs that insite.js

Uncaught Reference error:Jquery is not defined .

Can you please help me understand why I am getting the console error when loading the scripts from a WordPress plugin?

share|improve this question

marked as duplicate by Chip Bennett, ialocin, s_ha_dum, toscho Jan 21 '14 at 15:10

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.

Once you are loading the scripts correctly (via Rachel Baker's answer), I would wager that the errors are coming from the actual code in the jquery-ticker.js and site.js scripts.... which would tend to make this off-topic (ie: more jQuery-related than WordPress-related) – helgatheviking Jan 20 '14 at 22:29
@helgatheviking I should add jQuery.noConflict(); and this solve the problem .thank you – ashraf Jan 21 '14 at 2:13
Close-voted as too localized. The jQuery no-conflict issue has been asked and answered several times at WPSE. – Chip Bennett Jan 21 '14 at 14:08

Add the jquery script as a dependency for your jquery-ticker.js and site.js files within the wp_enqueue_script function.


function bbc_frontend_script() {
wp_enqueue_script('ticker', plugins_url("/js/jquery-ticker.js", __FILE__), array( 'jquery' ) );
wp_enqueue_script('sitejs', plugins_url("/js/site.js", __FILE__), array( 'jquery', 'ticker' ) );
add_action( 'wp_enqueue_scripts', 'bbc_frontend_script' );

You also don't have to enqueue jquery separately if you define it as a dependency.

Edited: Added missing ) at end of enqueue statements.

share|improve this answer
thank you .but I am getting error :object has no method ticker – ashraf Jan 20 '14 at 18:12
Where are you getting the error message? Is it a Javascript error or a PHP error? – Seamus Leahy Jan 20 '14 at 18:46
I apologize I missed an ) within the code. I have updated my answer. – Rachel Baker Jan 20 '14 at 19:03
Jquery error.Object has no method...... – ashraf Jan 20 '14 at 19:03
I have placed ) btw thank you for help – ashraf Jan 20 '14 at 19:04

Check your examples. You are using plugins_url, but on your other example you say they are in the template directory.

Where are these js files actually located?

share|improve this answer

You need to register the scripts but also define them to the jQuery library e.g.

  wp_register_script('ticker', plugins_url("/js/jquery-ticker.js", array('jquery'), '1.3', true );

The array registers it after jQuery is loaded and the true is to set it to register in wp_footer and not wp_head

share|improve this answer
You don't need to register them first. You can enqueue them directly with wp_enqueue_script(). – helgatheviking Jan 20 '14 at 22:27

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