Enqueue script only for IE

WordPress has a $is_IE global variable: global $is_IE; if($is_IE) enqueue_script(…); Personally I prefer the IE conditional comments. Other browsers ignore them anyway, so there’s no reason to use PHP for browser detection. You might also want to consider using 8 bit alpha PNG images instead of 24 bit PNGs, which don’t need any javascript fix … Read more

Get the list of enqueued/registered scripts for a specific post?

I’m not familiar with Gutenberg, but as you mentioned it as an example, I assume you didn’t mean “only” Gutenberg. The wp_enqeue_script() or wp_enqueue_style() functions do not accept arguments regarding posts or pages. The script are registered and rendered globally. If a script is output on certain posts only, then it has to be a … Read more

jquery script not enqueued in child theme

There are two parts in the question I want to address: It didn’t work because the action uses a plural form: wp_enqueue_scripts, not wp_enqueue_script. I guess this happened, because the function you have to use here – wp_enqueue_script() – does use a singular. You should not use the function wp_enqueue_script() with so many parameters. Register … Read more

Hyphens vs. periods in the script slug in wp_register_script?

Use hyphens only. Take a look at wp-includes/script-loader.php: $scripts->add( ‘scriptaculous-sound’, ‘/wp-in $scripts->add( ‘scriptaculous-controls’, ‘/wp $scripts->add( ‘scriptaculous’, ”, array(‘sc // not used in core, replaced by Jcrop.js $scripts->add( ‘cropper’, ‘/wp-includes/js/cr $scripts->add( ‘jquery’, ‘/wp-includes/js/jqu // full jQuery UI $scripts->add( ‘jquery-ui-core’, ‘/wp-include $scripts->add( ‘jquery-effects-core’, ‘/wp-in $scripts->add( ‘jquery-effects-blind’, ‘/wp-i $scripts->add( ‘jquery-effects-bounce’, ‘/wp- $scripts->add( ‘jquery-effects-clip’, ‘/wp-in $scripts->add( ‘jquery-effects-drop’, ‘/wp-in $scripts->add( … Read more

wp_enqueue script my_javascript_file in the footer

You have true set in the 4th parameter (version), not the 5th. wp_enqueue_script( ‘my_javascript_file’, //slug get_template_directory_uri() . ‘/javascripts/app.js’, //path array(‘jquery’), //dependencies false, //version true //footer ); Also, as someone else mentioned, drop jquery enqueue, you’ve got it as a dependency, you don’t need to enqueue it as well. One last thing, your function name has … Read more

Why is jquery-ui-core enqueueing in my footer instead of the header?

Why do you need it in the header? It’s enqueuing in the footer because when it was registered it was set to enqueue in the footer. In wp-includes/script-loader.php: $scripts->add( ‘jquery-ui-core’, ‘/wp-includes/js/jquery/ui.core.js’, array(‘jquery’), ‘1.8.12’ ); $scripts->add_data( ‘jquery-ui-core’, ‘group’, 1 ); The second line forces it to load in the footer. You could deregister the script, then … Read more

Notice that the wp_enqueue_style is not being called correctly!

The problem is that the wp_enqueue_style() call is inside of the category_collapse() member function of the CategoryCollapse() class, and the CategoryCollapse() class is being instantiated by a callback hooked into the plugins_loaded action hook. That means that the wp_enqueue_style() function is attempting to execute at the plugins_loaded hook, which fires before init, wp_enqueue_scripts, and admin_enqueue_scripts. … Read more