0

Here is how I am enqueueing the script (this is inside a class):

add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts'), true);

public function add_admin_scripts(){
    $parentBase = get_current_screen();
    if($parentBase->id == 'toplevel_page_calc-settings'){
            wp_enqueue_style( 'l7w-admin-js', $this->pluginUrl . 'assets/js/admin.min.js');
    }
}

Here is the simple script:

$(document).ready(function(){
    alert("Works");
    console.log('Works');
});

The js is showing and is loaded on the settings page but the alert() and the console.log() are not executed.

Why am I not seeing the alert or the console.log()?

3
  • You should see an error in your console related to the $, WordPress' jQuery object reference is jQuery, not $. Commented Sep 8, 2017 at 20:20
  • I am seeing this warning: Resource interpreted as Stylesheet but transferred with MIME type application/javascript Commented Sep 8, 2017 at 20:23
  • 1
    oh, you're using wp_enqueue_style instead of wp_enqueue_script. Commented Sep 8, 2017 at 20:25

1 Answer 1

0

Got it:

wp_enqueue_style( 'l7w-admin-js', $this->pluginUrl . 'assets/js/admin.min.js');

wp_enqueue_script( 'l7w-admin-js', $this->pluginUrl . 'assets/js/admin.min.js');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.