| @@ -17,5 +17,23 @@ | ||
| 17 | 17 | wp_enqueue_script( 'wp-block-directory' ); |
| 18 | 18 | wp_enqueue_style( 'wp-block-directory' ); |
| 19 | 19 | } |
| 20 | 20 | add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_block_editor_assets_block_directory' ); |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Add data attribute of handle to all script tags output in the wp-admin. | |
| 24 | + * | |
| 25 | + * @param string $tag The `<script>` tag for the enqueued script. | |
| 26 | + * @param string $handle The script's registered handle. | |
| 27 | + * | |
| 28 | + * @return string Filter script tag. | |
| 29 | + */ | |
| 30 | + function gutenberg_change_script_tag( $tag, $handle ) { | |
| 31 | + if ( ! is_admin() ) { | |
| 32 | + return $tag; | |
| 33 | + } | |
| 34 | + $tag = str_replace( '<script ', sprintf( '<script data-handle="%s" ', esc_attr( $handle ) ), $tag ); | |
| 35 | + | |
| 36 | + return $tag; | |
| 37 | + } | |
| 38 | + add_filter( 'script_loader_tag', 'gutenberg_change_script_tag', 10, 2 ); | |
| 21 | 39 | } |