0

I'm working on a plugin that relies on several JS scripts. In my plugin file (graph-plugin.php) I've the following function:

function initialize_scripts() {
    wp_register_script( 'int-flot', WP_PLUGIN_URL . '/wp-graph-test/js/init-flot.js', array ( 'jquery' ), NULL, true);
    wp_enqueue_script( 'int-flot' );
    wp_register_script( 'int-dtpck', WP_PLUGIN_URL . '/wp-graph-test/js/init-datepickers.js', array ( 'jquery' ), NULL, true);
    wp_enqueue_script( 'int-dtpck' );
} 
add_action( 'wp_enqueue_scripts', 'initialize_scripts' );   

At the moment my functions should do console log and alert but that is not working.

jQuery(document).ready(function($) {

    console.log("REady");
    alert("ready");
});

One script should initialize js-flot and other should initialize ui-datepickers. Do I need to move my initialisation in functions.php file? I can see this scripts in the footer when I check in resources. Thank you!

0

Try to write it like this:

(function($) {$(document).ready(function(){...});})(jQuery);
  • Did you miss closing one pair of parentheses and braces? I've tried with added closing parenthesis and braces but still no luck. Is it better idea to move the script to the function? – Moirae Dec 8 '15 at 9:59
  • Unfortunately there is still no result. The code actually works fine when not implemented as a plugin – Moirae Dec 8 '15 at 10:11

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.