Skip to content

Instantly share code, notes, and snippets.

@onishiweb
Last active August 29, 2015 14:07
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 onishiweb/bd4f457b650bb6bbaeb0 to your computer and use it in GitHub Desktop.
Save onishiweb/bd4f457b650bb6bbaeb0 to your computer and use it in GitHub Desktop.
/**
* Read the contents of the theme CSS file into a variable and ouput.
**/
function ajo_inline_styles() {
$css_file = get_stylesheet_uri(); // This will load the entire theme stylesheet in the head (only recommended if it's small)
// to include specific CSS use: `get_template_directory_uri() . '/path-to-above-the-fold.css'
$css = file_get_contents($css_file);
echo "<style>{$css}</style>";
}
// Run the function in the wp_head action
add_action( 'wp_head', 'ajo_inline_styles', 40 );
@onishiweb
Copy link
Author

Just updated to include some comments about including the entire theme directory CSS vs. an "above the fold" CSS file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment