0

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' );
}
add_action('wp_enqueue_scripts','you_fancy_js');
add_action('admin_head','you_fancy_js');

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

  • @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. – fuxia Jul 6 '12 at 16:20
2

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' );
}
add_action('wp_enqueue_scripts','you_fancy_js');

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.

  • <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"></script> <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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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