JQuery datepicker working in interface but not wordpress admin dash

I have current code to host jQuery Date Picker:

function register_my_scripts()
{
    wp_register_script('scripts', plugins_url('/js/scripts.js', __FILE__));
    wp_enqueue_script('scripts');
    wp_enqueue_script('jquery-ui-datepicker');
}

function register_my_styles()
{
    wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
}

add_action('wp_enqueue_scripts', 'register_my_scripts');
add_action('wp_enqueue_scripts', 'register_my_styles'); 

jQuery function, which is inside scripts.js:

jQuery(document).ready(function(){
    jQuery('.datepicker').datepicker({
        dateFormat : 'D, m/d/yy'
    });
});

and html field:

<input type="text" class="datepicker"/>

This code works fine on the front panel, but for some reason does nothing on the rear panel. I only need this to work on the backend.

What's going on here?

+4
source share
1 answer

You may need to service your scripts admin_enqueue_scriptsinsteadwp_enqueue_scripts

add_action('admin_enqueue_scripts','register_my_scripts');

See this link for more details.

0
source

All Articles