For scripts you can use the script_loader_tag
filter, which is run right before the script tag is output. It filters the HTML <script>
tag, but it also passes the handle and URL that you can use to extract the contents and replace the script tag with a version that has the script inline:
function wpse_292955_inline_script( $script, $handle, $src ) {
if ( $handle === 'script-handle' ) {
$script = sprintf( '<script type="text/javascript">%s</script>', file_get_contents( $src ) );
}
return $script;
}
add_filter( 'script_loader_tag', 'wpse_292955_inline_script', 10, 3 );
There’s also style_loader_tag
for styles:
function wpse_292955_inline_style( $html, $handle, $href, $media ) {
if ( $handle === 'style-handle' ) {
$html = sprintf(
'<style type="text/css" media="%s">%s</style>',
esc_attr( $media ),
file_get_contents( $href )
);
}
return $html;
}
add_filter( 'style_loader_tag', 'wpse_292955_inline_style', 10, 4 );
Note that because scripts and styles are registered with a URL the URL will need to be accessible by your server for file_get_contents()
to work, so it probably won’t work in a local development environment.