I'm new to jquery and php and trying to create my first Wordpress Plugin. The plugin simply adds a metabox to posts which has a date field on the backend.
Metabox and field all added ok and appear when I go to create or edit a post.
However, I can't get the datepicker to work. Nothing happens when you click on the input box, the date selector does not show. Although the input box will only let me input numbers not letters.
The plugin is a single page of php code.
The top of my plugin file attempts to load the jquery:
function ca_load_jquery_datepicker() {
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css');
}
add_action( 'admin_enqueue_scripts', 'ca_load_jquery_datepicker' );
Then this is the input and jquery in my form (lower down on the plugin file):
<input type="text" class="date" name="ca_expiry_date" value="">
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.date').datepicker({
dateFormat : 'yy-mm-dd'
});
});
</script>
Can anyone help advise where I am going wrong with the datepicker? Thank you!
UPDATE
Thanks for the comments, I have discovered that if I instal the "Classic Editor" plugin, my code works. But when that is not activated and using Gutenberg it does not work.
The error is (without sharing the site url): GET https://xxxx.co.uk/wp-content/themes/publisher/gutenberg-7.6.2.min.css?ver=7.6.2 net::ERR_ABORTED 404 (Not Found)
This error is still there even when my plugin is disabled.
However, if I activate the Twenty Nineteen theme there is no error but the date field in my plugin still does not work.
So clearly gutenberg does not like something in my code...