最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

What is the propre way to include jQuery UI Datepicker's CSS in plugin?

matteradmin5PV0评论

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.

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.

Share Improve this question asked Apr 11, 2019 at 15:30 TTTTTT 3291 gold badge4 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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.

Post a comment

comment list (0)

  1. No comments so far