I am attempting to implement a jQuery UI dialog in Wordpress 4.5.3, but it only works about half the time. The rest of the time I get the following error:
Uncaught TypeError: jQuery(...).dialog is not a function lwr_jquery_dialog.js(2)
I have enqueued the scripts as follows, and verified they load in the correct order on the page:
function enqueue_jquery_dialog() {
wp_enqueue_script('jquery-ui-dialog', false, array('jquery','jquery-ui-core'),
false, true );
wp_enqueue_script('lwr_dialog', get_stylesheet_directory_uri() .
'/js/lwr_jquery_dialog.js', array('jquery-ui-dialog') );
}
add_action( 'wp_enqueue_scripts', 'enqueue_jquery_dialog' );
In lwr_jquery_dialog.js I have:
jQuery(document).ready(function() {
jQuery('#dialog').dialog({
width: 600,
modal: true,
resizable: false,
draggable: false,
});
});
And here's the actual dialog function in functions.php
function add_jquery_dialog() {
?>
<div id="dialog" title="Today Only">
DIALOG TEXT HERE
</div>
<?php
}
add_action('wp_footer', 'add_jquery_dialog');