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.

Hi guys I have added jQuery and my jQuery fail to my main plugin page and it works great by this was.

    function load_scipt() {
        wp_register_script( 'reserveit', plugins_url( '/js/reserveit.js', __FILE__ ), array( 'jquery' ), '2.5.1' );
        wp_enqueue_script( 'reserveit' );

        wp_register_script( 'datetimepicker', plugins_url( '/lib/datetimepicker/js/jquery-ui-timepicker-addon.js', __FILE__ ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-slider', 'jquery-ui-datepicker' ) );
        wp_enqueue_script( 'datetimepicker' );

        wp_enqueue_script( 'jquery-ui-core' );
        wp_enqueue_script( 'jquery-ui-datepicker' );
        wp_enqueue_script( 'jquery-ui-slider' );
        wp_enqueue_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
    }

    add_action( 'wp_enqueue_scripts', 'load_scipt' );


Now I need to add jQuery datepicker to input in my admin menu, but it isn't working here is the code.

function load_scipts() {
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'jquery-ui-datepicker' );
    wp_enqueue_script( 'jquery-ui-core' );
    wp_enqueue_script( 'jquery-ui-widget' );


    wp_register_script( 'admin-menu', plugins_url( 'admin-menu.js', __FILE__ ), array( 'jquery', 'jquery-ui-datepicker' ), '2.5.1' );
    wp_enqueue_script( 'admin-menu' );
    wp_enqueue_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
}

  add_action( 'wp_enqueue_scripts', 'load_scipts' );

I tried everything but it isn't working. my path to files working but I have no idea where can the problem is.

this is my reserveit.js

jQuery(document).ready(function($) {

    jQuery('#datepicker').datepicker({
        dateFormat: 'dd-mm-yy'
    });

});

and this is my admin-menu.js

jQuery(document).ready(function(jQuery) {

    jQuery('#datepicker').datepicker({
        dateFormat: 'dd-mm-yy'
    });
});

Please if you have idea write comment.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

If you are trying to enqueue scripts for admin requests, you need to use the hook admin_enqueue_scripts. wp_enqueue_scripts is only for front end requests.

share|improve this answer
    
Thank you now is finally working. –  pstanev Dec 18 '13 at 17:10

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.