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

My code for include js as follows:

function you_fancy_js(){
    wp_register_script( 'custom-script', plugins_url( '/js/jquery.js', __FILE__ ), array( 'jquery', 'jquery-ui-1.8.18.custom.min', 'jquery.validate.min' ) );  
    wp_enqueue_script( 'custom-script' );

The above code should include a js file. It is not working.

share|improve this question
@Joseph Leaving notes to OP inside the edit, is not kool. It doesn't improve the question - please use comments for that. – kaiser Jul 6 '12 at 14:56
@Himanshu Do not spread information about your problem in comments. Update your question instead. – toscho Jul 6 '12 at 16:20

Your uses of wp_register_script and add_action are incorrect. Try the following code:

function you_fancy_js(){
    wp_register_script( 'custom-script', plugins_url( '/js/jquery.js', __FILE__ ), array( 'jquery', 'jquery-ui-core', 'jquery-validate' ) );  
    wp_enqueue_script( 'custom-script' );

This assumes that your custom jQuery functions are in jquery.js and jquery, jquery-ui-core, and jquery-validate are already enqueued. You do not need admin_head. The admin equivalent of wp_enqueue_scripts is admin_enqueue_scripts.

share|improve this answer
<script type="text/javascript" src="<?php bloginfo('wpurl'); ?>/wp-content/plugins/svipl_portfolio/js/jquery.js"></script> <script type="text/javascript" src="<?php bloginfo('wpurl'); ?>/wp-content/plugins/svipl_portfolio/js/jquery-ui-1.8.18.custom.min.js"></scrip‌​t> <script type="text/javascript" src="<?php bloginfo('wpurl'); ?>/wp-content/plugins/svipl_portfolio/js/jquery.validate.min.js"></script> – Himanshu Jun 29 '12 at 13:08
If you are in the admin panel, jQuery and possibly jQuery UI should already be loaded. If not, add wp_enqueue_script('jquery') and wp_enqueue_script('jquery-ui-core') followed by your validation script before your custom script(s). There is no need to bring your own versions of jQuery and jQuery-UI as they are already included with WordPress. – Joseph Leedy Jun 29 '12 at 14:26

jQuery is already a part of the core package and may very well already have been enqueued by a plugin or by the theme if you are modding a theme rather than writing from scratch. Including it again with a handle other than jQuery is likely to run into problems even if your code worked.

If you are going to enqueue jQuery from a source other than the core it is best to deregister it and then register your source before enqueue.

You should also use the init hook to attach your script function and leave the core jQuery inclusion alone when in the admin.

Finally, there are a number of good reasons to de-register the included jQuery and include the one from the Google AJAX repository.

Try this:

 * Add jQuery from Google ajax library
function dmm_add_jquery() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', false, '1.3.2');
add_action('init', 'dmm_add_jquery');
share|improve this answer
Never replace the default jQuery without pressure. It isn’t even delivered compressed to all browsers. – toscho Jul 6 '12 at 14:32
Yeah, please do not ever do this. – Pippin Jul 6 '12 at 14:33
1. Decresead latency (it's on a CDN) 2. Increased parallelism 3. It may already be cached for a first time visitor trumps you concern over it being uncompressed every time. – Dane Morgan Jul 6 '12 at 14:56
Here's the reason, why people still believe in the myth. Take a look at the search string and compare it to the results... ;) – kaiser Jul 6 '12 at 15:02
[Why should I use Google's CDN for jQuery? | stackoverflow] (stackoverflow.com/questions/2180391/…) More reasons. And why I do this with every install. – Dane Morgan Jul 6 '12 at 15:10

Your Answer


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.