Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created April 5, 2018 03:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cameronjonesweb/0216c498928be97e056564e4f5c78724 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/0216c498928be97e056564e4f5c78724 to your computer and use it in GitHub Desktop.
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