Last active
August 29, 2015 14:07
-
-
Save onishiweb/bd4f457b650bb6bbaeb0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just updated to include some comments about including the entire theme directory CSS vs. an "above the fold" CSS file.