Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datepicker working in front end but not wordpress admin dash

I have the current code for enqueuing the 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'); 

the jQuery function which is inside scripts.js:

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

and the html field:

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

This code work fine on the front end but for some reason doesn't do anything on the back end. I only need it to work on the backend.

What's going on here?

like image 549
mgrantnz Avatar asked Nov 09 '22 13:11

mgrantnz


1 Answers

Probably, you need to serve your scripts on admin_enqueue_scripts instead of wp_enqueue_scripts

add_action('admin_enqueue_scripts','register_my_scripts');

See this link for more details

like image 159
smnbbrv Avatar answered Nov 14 '22 22:11

smnbbrv