wp_script_add_data not working

the wp_script_add_data() method itself is not adding async attribute to the script tag. It just add a metadata to the script. As examples were already given earlier in few answers the following could work for you: wp_enqueue_script(‘pledge-js’, ‘https://www.pledge.to/assets/widget.js’, array( ‘jquery’ ), null, true); wp_script_add_data( ‘pledge-js’, ‘async’, true); add_filter(‘script_loader_tag’, ‘async_scripts’, 3, 10); function async_scripts($tag, $handle, $src) … Read more

What is the standard way to use the version of React that ships with Gutenberg on the front end?

I found it, wp-element. The @wordpress/scripts should handle the heavy lifting of transforming the JSX in the proper way. add_action( ‘wp_enqueue_scripts’, ‘my_enqueue_plugin_js’ ); // Loads on frontend function my_enqueue_plugin_js() { wp_enqueue_script( ‘my-plugin-frontend’, plugin_dir_url( __FILE__ ) . ‘js/plugin.js’, [‘wp-element’] ); } Once we do this we will have window.wp.element available in our JavaScript. This contains the … Read more

How can I specifically enqueue scripts for edit orders pages only

You can do it by checking current post_type. For woocommerce order page, post type is shop_order. So try to change your code as follows. function selectively_enqueue_admin_script_js_for_edit_address($hook) { global $post; if ($post->post_type === ‘shop_order’) { if ($hook === ‘post.php’ || $hook === ‘post-new.php’) { wp_enqueue_script(‘artio-wc-admin-order-page-mod’, ‘/wp-content/plugins/custom_wc_mods/order_page/paste_payment_instructions_and_prompts_into_shipping_address_form_v2.js’, array(), date(“h:i:s”)); /* https://stackoverflow.com/a/31834007 */ /* During development, you could … Read more

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 changed. If this understanding is correct, then you may do the following: function my_custom_theme_scripts() { $ads_version = filemtime( get_stylesheet_directory() . ‘/js/ads.js’ … Read more