Created
December 14, 2018 19:09
-
-
Save ksk1015/0493ce3f1b8d9bc2f722559822fa48a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_enqueue_inline_script ($handle, $src = false, $deps = array(), $ver = false, $in_footer = false) { | |
if ( $src ) { | |
wp_enqueue_script( $handle, $src, $deps, false, $in_footer ); | |
} | |
add_filter( 'script_loader_tag', function ( $tag, $this_handle, $src ) use ($handle) { | |
if ($this_handle !== $handle) { | |
return $tag; | |
} | |
$url = explode('?', $src)[0]; | |
$path = str_replace(site_url(), ABSPATH, $url); | |
$script = file_get_contents( $path ); | |
return "<script>// $url\n$script\n</script>\n"; | |
}, 10, 3 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment