Cannot exclude JavaScript files that are registered but not enqueued
-
Is it true that JavaScript files registered via
wp_register_script
, but not enqueuded viawp_enqueue_script
by default cannot be excluded from JavaScript combining? There are many plugins that only enqueue JavaScript files when, for example, there is a shortcode on a page. Sometimes it is necessary that these files are also excluded from JavaScript combination. If this is the case, it would be nice if registered scripts could also be excluded./** * Get styles and scripts loaded on the site. * * @since 5.2.0 * * @return arary $data Array of all styles and scripts loaded on the site. */ public function get_assets() { // Get the global varialbes. global $wp; global $wp_styles; global $wp_scripts; // Remove the jet popup action to prevent fatal errros. remove_all_actions( 'elementor/editor/after_enqueue_styles', 10 ); $wp_scripts->queue[] = 'wc-jilt'; ob_start(); // Call the action to load the assets. do_action( 'wp', $wp ); do_action( 'wp_enqueue_scripts' ); do_action( 'elementor/editor/after_enqueue_styles' ); ob_get_clean(); unset( $wp_scripts->queue['wc-jilt'] ); // Build the assets data. return array( 'scripts' => $this->get_assets_data( $wp_scripts ), 'styles' => $this->get_assets_data( $wp_styles ), ); }
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Cannot exclude JavaScript files that are registered but not enqueued’ is closed to new replies.