Skip to content

Instantly share code, notes, and snippets.

@loorlab
Forked from cameronjonesweb/add-script-handle.php
Created June 24, 2019 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loorlab/7e2bc3c632a39e240c3086218ed9d14b to your computer and use it in GitHub Desktop.
Save loorlab/7e2bc3c632a39e240c3086218ed9d14b to your computer and use it in GitHub Desktop.
Display Handle Name JS WordPress - Add the script handle to enqueued script tags
<?php
add_filter( 'script_loader_tag', 'cameronjonesweb_add_script_handle', 10, 3 );
function cameronjonesweb_add_script_handle( $tag, $handle, $src ) {
return str_replace( '<script', sprintf(
'<script data-handle="%1$s"',
esc_attr( $handle )
), $tag );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment