Load js/css files only on specific admin UI pages

The right hooks // Use both for scripts & styles *) wp_enqueue_scripts // (for the frontend) login_enqueue_scripts // (for the login screen) admin_enqueue_scripts // (for the admin dashboard) *) Read this article @wpdevel. Further reading in the Codex about the three hooks admin_menu network_admin_menu user_admin_menu On the admin_enqueue_scripts hook, you have an argument as well: … Read more

Add a script as a dependency to a registered script

Digging through https://github.com/WordPress/WordPress/blob/3.5.1/wp-includes/class.wp-dependencies.php all registered scripts are stored in the global $wp_scripts. You can access them directly through that, but I prefer to use the API when it exists. In this case, $wp_scripts->query() returns a particular registered script (a _WP_Dependency object – see source). A _WP_Dependency object stores the dependencies as an array of handles, … Read more

Correct Method to run scripts with dependencies without enqueue?

function script_that_requires_jquery() { wp_register_script( ‘script-with-dependency’, ‘http://www.example.com/script-with-dependency.js’, array( ‘jquery’ ), ‘1.0.0’, true ); wp_enqueue_script( ‘script-with-dependency’ ); } add_action( ‘wp_enqueue_scripts’, ‘script_that_requires_jquery’ ); This is the correct method to enqueue scripts (and styles for that matter). You should always be using wp_enqueue_scripts to hook scripts and styles to. There are a few thing here to check when you … Read more

Register and enqueue conditional (browser-specific) javascript files?

WP_Scripts and WP_Styles classes are behind wp_enqueue_script and wp_enqueue_style functions. If you take a look at classes implementation (scripts and styles) then you will see that WP_Scripts class doesn’t support any kind of conditional scripts, but! you can see that WP_Styles does! The problem is that wp_enqueue_style doesn’t allow you to setup condition. So we … Read more

wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i’m confused

wp_print_scripts is the action that runs when scripts are output to the template. wp_register_script and wp_enqueue_script are functions for registering/enqueueing scripts to be output when wp_print_scripts runs. you can’t register or enqueue styles in the wp_print_scripts action hook because styles have already been output in the wp_print_styles hook, which runs before wp_print_scripts. refer to the … Read more

How to properly dequeue scripts and styles in child theme?

You are very nearer to the solution, because you are on the right path. Just to tweak a little bit: There are two such action hooks: wp_print_scripts, and wp_print_styles So the way you can do it, is: hook ’em differently: //Dequeue Styles function project_dequeue_unnecessary_styles() { wp_dequeue_style( ‘bootstrap-map’ ); wp_deregister_style( ‘bootstrap-map’ ); } add_action( ‘wp_print_styles’, ‘project_dequeue_unnecessary_styles’ … Read more

Check if a script/style was enqueued/registered

There is a function called wp_script_is( $handle, $list ). $list can be one of: ‘registered’ — was registered through wp_register_script() ‘queue’ — was enqueued through wp_enqueue_script() ‘done’ — has been printed ‘to_do’ — will be printed Ditto all that for wp_style_is().

Where is the right place to register/enqueue scripts & styles

Why registering and queuing properly matters it should be in time – earlier than script/style is up for being output to page, otherwise it is too late; it should be conditional – otherwise you are loading stuff where you don’t need it and cause performance and functionality issues, for this you need WP environment loaded … Read more