Conditionally load script depending on current admin page

You can do something like this add_action( ‘admin_menu’, ‘my_admin_menus’ ); function my_admin_menus() { $GLOBALS[‘my_page’] = add_menu_page( ‘Page Title’, ‘Menu Title’, MY_ADMIN_CAPABILITY, ‘menu-slug’, ‘show_page_content’); } add_action( ‘admin_enqueue_scripts’, ‘enqueue_admin_js’); function enqueue_admin_js($hook) { if($GLOBALS[‘my_page’] === $hook) { wp_enqueue_script( ‘jquery-ui-core’ ); wp_enqueue_script( ‘jquery-ui-tabs’ ); // Isn’t it nice to use dependencies and the already registered core js files? wp_enqueue_script( … Read more

JavaScript enque stopped working

I am not sure if you posted code as-is or extracted part of it, but per this snippet – you are hooking function inside itself. Which doesn’t seem like it will work nicely. 🙂 Also init hook should not be used for enqueue, on front-end hook to use is wp_enqueue_scripts, see where is the right … Read more

How do I get jQuery to Load before Bootstrap?

In place of your emnpty array() you are able to declare dependencies. For Script A to load before Script B, declare that A is dependent on B. Codex reference: http://codex.wordpress.org/Function_Reference/wp_enqueue_script It’s possible you have declared these dependencies within your register statements but these are not given above.

Custom script file enqueue has “?ver=4.5.1” when loading and doesn’t update

I agree with @Mark Kaplun – what you’re describing is an odd behavior though. Try this markup to override the $ver param. wp_enqueue_script( ‘script’, get_template_directory_uri() . ‘/js/script.js’, array ( ‘jquery’ ), null, true); https://developer.wordpress.org/themes/basics/including-css-javascript/ Alternatively, to work around the version cache try this markup which will generate a unique version with each page load. wp_enqueue_script( … Read more