Skip to main content
21 votes
Accepted

How can I get a list of all enqueued scripts and styles?

do_action doesn't quite work like that. When you call do_action('crunchify_print_scripts_styles') WP looks at its list of registered actions and filters for any that are attached to a hook called ...
Andy Macaulay-Brook's user avatar
17 votes

How can I get a list of all enqueued scripts and styles?

You could use wp_print_scripts and wp_print_styles actions to timely and properly access to enqueued scripts and styles, as these actions are the last events before scripts and styles are included in ...
cybmeta's user avatar
  • 20.5k
5 votes

How to properly dequeue scripts and styles in child theme?

This is not the proper way. WordPress said not to use both wp_print_scripts, and wp_print_styles since WordPress 3.3. Either you are enqueueing or dequeueing, the proper way is: function ...
Morshed Alam Sumon's user avatar
5 votes

How do I get the $handle for all enqueued scripts?

Is there some way to get the $handle for each script that has been enqueued? You could try inspecting $wp_scripts->queue at a specific hook but it won't give you a list of all handles used by ...
vhs's user avatar
  • 350
5 votes

How can I selectively print scripts to the footer of certain admin pages?

There is also another way to achieve this which allows you to build more dynamic scripts using the admin_footer hook, add_action('in_admin_footer', 'my_custom_admin_page'); function ...
Aurovrata's user avatar
  • 1,336
5 votes

Auto updating JavaScript dependancy in functions.php

If I understood your question correctly, you have two JavaScript files: ads.js and banner.js. You want the site to load the updated version of both of these files, whenever any of these files are ...
Fayaz's user avatar
  • 8,937
4 votes
Accepted

Wordpress doesn't Load JQuery Now? Do I need to enqueue JQuery also?

Your issue is that you are trying to use the normal jQuery shortcut ($) which doesn't work by default as the WordPress version of jQuery is in compatibility mode. You need to wrap the code in your ...
Erbilacx's user avatar
  • 391
4 votes
Accepted

wp_register_script multiple identifiers?

To have the JavaScript Libraries not to load since you already created a bundle of them, do the following: Asumming the following, usual enqueue: function the_js() { wp_enqueue_script('bundle_js'...
David Lee's user avatar
  • 3,891
4 votes
Accepted

Loading newest dependency javascript module file in functions.php

The problem Import statement like: import { export1 } from "./module-name.js"; is called static import declaration. Dynamic query string (to force load the latest file) cannot be used in ...
Fayaz's user avatar
  • 8,937
3 votes
Accepted

How can I add my script to admin using script-loader.php?

I think you'e are only registering it with: $scripts->add( 'user-profile-validator', ...) but not enqueueing it. Check e.g. how wp_register_script() is a wrapper for the WP_Scripts::add() ...
birgire's user avatar
  • 67.4k
3 votes
Accepted

How to avoid loading same script twice?

You can use a prefix like 'xyz-' (basically a namespace) for the handle if the script or stylesheet you use is unique to your theme / plugin. Owl Carousel is not, so just 'owlcarousel' is fine. You'd ...
iguanarama's user avatar
3 votes

How to cancel `wp_print_scripts`?

There is a way, but it's not recommended since there might be some other inline scripts attached to the enqueued scripts. You can hook to the wp_enqueue_scripts action and empty the global $wp_scripts ...
Johansson's user avatar
  • 15.3k
3 votes

How to properly dequeue scripts and styles in child theme?

For Dequeue Scripts, don't add the last "-js" or "-css" on ID part. I was using WordPress 5.8. It works for me. ABOVE CODE: //Dequeue JavaScripts function ...
Chandra Shekhar Pandey's user avatar
3 votes

How to remove some external js files from source?

You can use wp_dequeue_script to achieve this assuming they are using wp_enqueue_script to add the scripts in the first place. Learn more about enquene and dequeue: https://developer.wordpress.org/...
Liam Stewart's user avatar
3 votes

Writing scripts using Wordpress / WooCommerce classes?

Is there a proper way to easily bootstrap all the Wordpress includes, without having to go all the way through the theme? That's the wrong question. Shortcodes are far from the only way to run code ...
Jacob Peattie's user avatar
3 votes
Accepted

wp_add_inline_script not adding when script_loader_tag filtered

The reason this is happening is because the markup that is filtered by script_loader_tag includes the inline scripts. So when you filter it and replace all the HTML tag for a particular script, your ...
Jacob Peattie's user avatar
2 votes

Best way to create a user programatically

Use WP-CLI's User Create and put in a script. wp user create - Create a user. $ wp user create testuser8 [email protected] --user_pass=apsswd--role=author --send-email Success: Created user 3.
jgraup's user avatar
  • 9,764
2 votes

How can I get a list of all enqueued scripts and styles?

my solution for this is : make an option field in db activate sessions and secure them Functions I used I've start whit two functions from user cybmeta : just add a handle to result. function ...
Stoian Delev's user avatar
2 votes

wp_enqueue_script was called incorrectly Issue when active plugins of WordPress Admin Bar Improved

To use wp_enqueue_script() correctly, you need to launch your function with the action wp_enqueue_scripts. In your __construct() or init function add_action('wp_enqueue_scripts', array($this, '...
Benoti's user avatar
  • 2,436
2 votes

Load scripts for do_shortcode( ' [ my_shortcode ] ' )

Add a filter to pre_do_shortcode_tag and check if $tag is the same as your shortcode tag. If it is, enqueue a script in the footer. add_filter( 'pre_do_shortcode_tag', function( $a, $tag, $attr, $m ) ...
Nathan Johnson's user avatar
2 votes

Disable unneeded scripts in a wordpress installation

This seems like far too much to me granted a lot of those files seem very necessary, what I tend to do it open each of those scripts and compile them into a single file and then unhook each of them as ...
Nicholas Koskowski's user avatar
2 votes

How to use custom Javascript code inside a plugin?

Look into wp_register_script() and wp_enqueue_script(). You may be able to get by with only the latter. Pay special attention for your case of wanting it before the closing </body> that you ...
hwl's user avatar
  • 2,135
2 votes
Accepted

Why is JavaScript being added to header as application/oembed?

The oEmbed discovery link tags are added by core in wp_oembed_add_discovery_links() since version 4.4. See the changeset here. When we enqueue scripts in the footer, we have to make sure the ...
birgire's user avatar
  • 67.4k
2 votes

How to remove some external js files from source?

Firstly: Are you absolutely sure that you don't need them? Secondly: I'm assuming small-menu.js is for the mobile menu and wp-embed.min.js you want in case you use embeds. If I'm right, then you ...
Nicolai Grossherr's user avatar
2 votes
Accepted

Hardening uploads folder in IIS breaks images

I don't know if that is the right way but the last time I worked with IIS, I used this code to prevent the loading of an PHP script in the uploads folder. <?xml version="1.0" encoding="UTF-8"?> ...
user141080's user avatar
2 votes
Accepted

How can I load an inline script after the enqueued scripts in admin?

I finally found the answer. I need to use the admin_print_footer_scripts action. This will add scripts after the scripts that were called with wp_enqueue_scripts.
ShoeLace1291's user avatar
2 votes

Unable to load stylesheets and scripts to plugin settings page

The way to go was to use wp_enqueue_style() and wp_enqueue_script functions when admin_enqueue_scripts hooks. To register styles and scripts with wp_register_style and wp_register_script respectively ...
Vijay Chavda's user avatar
2 votes

Loading jQuery in the footer after removing jQuery migrate?

There is much safer way of removing jquery-migrate... Your code is almost correct, but first you remove jQuery and then add it again. If dependencies for jQuery will change, then your code will cause ...
Krzysiek Dróżdż's user avatar
2 votes
Accepted

Select2 in WordPress

It's not. They may have been planning it for 4.1 or 4.2, as suggested in your link, but for whatever reason it never happened. You can see a list of core-registered scripts that you include here. ...
Jacob Peattie's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible