Hot answers tagged

42 votes
Accepted

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, ...
user avatar
17 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 ...
user avatar
16 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 ...
user avatar
  • 19.8k
8 votes

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(...
user avatar
7 votes

Best way to create a user programatically

You should read the codex page re wp_create_user. You don't describe the context in which your code runs. You shouldn't need all those require_once calls. Anyhow, in this line ...
user avatar
  • 4,900
5 votes
Accepted

Get list of scripts / styles and show file which enqueued them

This is not possible the way you think. It would maybe be possible if you use Reflections or debug_backtrace(), but there's no reliable way to do this. WordPress does not keep a stack or queue where ...
user avatar
  • 49.9k
4 votes
Accepted

How to get a jQuery script to run on a page?

Your question is a bit broad. We actually have a one question per post policy. I'm going to try to answer though My first question is, shouldn't most themes that you download out there ...
user avatar
4 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 ...
user avatar
  • 300
4 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 ...
user avatar
  • 1,168
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 ...
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'...
user avatar
  • 3,571
3 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 ...
user avatar
3 votes

How do I enqueue a JavaScript in my footer via the functions.php file?

Following code can be used to add script in footer BUT I should mention here that this is not the recommended way in WordPress. add_action( 'wp_footer', 'custom_footer_script', 100 ); function ...
user avatar
3 votes
Accepted

WordPress Script Loading/Unloading -- wp_deregister_script('jquery')

Wordpress has essentially two groups of methods to handle scripts, both of which should be used: wp_register_script Registers a script in Wordpress. It does not get called, it is just available for ...
user avatar
3 votes
Accepted

How do I load custom scripts and styles for a page?

Yes, you may add conditional tags to the wp_enqueue_scripts action. See the examples below: function load_assets() { wp_enqueue_style( 'styles', get_template_directory_uri() . '/css/styles.css');...
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 ...
user avatar
  • 14.7k
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 ...
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/...
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 ...
user avatar
2 votes

What is your best practice to execute one-time scripts?

Another way is to set a global wp_option when the work is done and check for that option every time the init hook is executed. function my_one_time_function() { // Exit if the work has already ...
user avatar
2 votes

WordPress Script Loading/Unloading -- wp_deregister_script('jquery')

Just to chip in,first of all, thanks for the complement, appreciated. You are using a child theme, of which the parent theme should have enqueued the jquery library built into wordpress. Like I said ...
user avatar
2 votes
Accepted

Overwrite or Replace code in WP_Footer

Since you ruled out remove_action there is only one way you can do it. And you've guessed it: preg_repalce, substr mixture but with a little help and PHP DOM add_action('wp_footer', '...
user avatar
  • 496
2 votes
Accepted

change $src from wp_register_script in plugins/themes

Well of course you can. All you need to find is what handle they are using for those scripts. let's say they are uing plugin-script handle. Then you deregister and register script again with your URL. ...
user avatar
  • 8,181
2 votes
Accepted

WP CLI theme install. Install a private repo?

I actually figured out a way to do this. First you use wget like this: wget --user username --ask-password -O path/to/output.zip https://bitbucket.org/path/to/file.zip the -O flag specifies output ...
user avatar
  • 358
2 votes
Accepted

wp_enqueue_script adds only the first script

You gave each each script the same handle/id of 'grid' Try something like this. function banana_scripts() { wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/jquery.min.js', ...
user avatar
2 votes
Accepted

Scripts not loading when using the wp_enqueue_scripts action

get_stylesheet_uri() loads the main stylesheet of the theme. If you need to load additional stylesheets, you need to use get_template_directory_uri() for parent themes and get_stylesheet_directory_uri(...
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 someone@gmail.com --user_pass=apsswd--role=author --send-email Success: Created user 3.
user avatar
  • 9,479
2 votes
Accepted

wp_enqueue_script with dependencies doesn't work

This is a bug in Wordpress. https://core.trac.wordpress.org/ticket/35873 As far as I can see, it can currently be fixed with https://core.trac.wordpress.org/attachment/ticket/35873/35873.3.patch, if ...
user avatar
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 ...
user avatar

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