Is it possible to enqueue a raw CSS string directly from within a template file?

Yes and no.

You can load a raw CSS string into the header programatically, but you can’t use wp_enqueue_style() to enqueue it. That function specifically loads files into the header in <link> tags.

But what you can do is something like this:

function print_inline_script() {
?>
<style type="text/css">
/* ... styles go here ... */
</style>
<?php
}
add_action( 'wp_head', 'print_inline_script' );

Leave a Comment