Title: Use has_block() function to enqueue block assets
Last modified: September 26, 2025

---

# Use has_block() function to enqueue block assets

 *  [slimpickins](https://wordpress.org/support/users/slimpickins/)
 * (@slimpickins)
 * [8 months, 2 weeks ago](https://wordpress.org/support/topic/use-has_block-function-to-enqueue-block-assets/)
 * Thank you for an absolutely wonderful plugin! It is light weight, straight to
   the point, and makes the Gallery block a perfect solution without additional 
   plugins. It would be great to see this in core.
 * I do see block assets are loaded on all pages. In testing with the base plugin
   I was able to load the JS and CSS file only when the block was loaded on the 
   page with the following:
 *     ```wp-block-code
       function ggbl_lightbox_scripts() {if (has_block('core/gallery')) {    wp_enqueue_style( 'ggbl_lightbox_css', plugin_dir_url( __FILE__ ) . 'ggbl-lightbox.css', array(), 1 );    wp_enqueue_script( 'ggbl_lightbox_js', plugin_dir_url( __FILE__ ) . 'ggbl-lightbox.js', array( 'jquery' ), 1, true );}}add_action( 'wp_enqueue_scripts', 'ggbl_lightbox_scripts' );
       ```
   
 * Any chance something similar can be added in the future?
 * Thanks again for the great work!

The topic ‘Use has_block() function to enqueue block assets’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gg-lightbox.svg)
 * [Gutenberg Gallery Blocks Lightbox](https://wordpress.org/plugins/gg-lightbox/)
 * [Support Threads](https://wordpress.org/support/plugin/gg-lightbox/)
 * [Active Topics](https://wordpress.org/support/plugin/gg-lightbox/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gg-lightbox/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gg-lightbox/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [slimpickins](https://wordpress.org/support/users/slimpickins/)
 * Last activity: [8 months, 2 weeks ago](https://wordpress.org/support/topic/use-has_block-function-to-enqueue-block-assets/)
 * Status: not resolved