0

I was looking for a datepicker, I read in another question's answer that jQuery UI's DatePicker is included in WordPress.

To make it work I needed to add in script inclusions

wp_enqueue_script('jquery-ui-datepicker');

But now it's missing .css,

I tried to add this in styles inclusions

wp_enqueue_style('jquery-ui-datepicker');

but it didn't work.

In the WordPress I'm working on, I found however thousands of references for datepicker. In the end I'm using this for now:

wp_enqueue_style( 'jquery-ui-datepicker', plugin_dir_url(__DIR__) . 'jetpack/modules/contact-form/css/jquery-ui-datepicker.css' );

But I feel like there must be a more "WordPress-native" syntax which I'd like to know.

2

The syntax is fine. WordPress doesn't include CSS for the jQuery UI components, so you need to include it yourself. This is what Jetpack has done, and it's why you're able to load it from there. However this means that your plugin is dependent on Jetpack. Ideally you'd download the CSS (you can get it here) yourself and include it in your own plugin/theme, and enqueue it from there.

  • Yes, in that case I will include the CSS in my plug-in, I expected WordPress to come with the CSS since it seems it comes with the JS. – TTT Apr 11 at 15:49

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.