Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Used to insert a CSS file <link> tag once no matter how often it's called. HTTP/2 inline CSS is why I wrote this.
<?php
// This is defined somewhere high up in functions.php
// $GLOBALS['cnmd_inline_css_record'] = array();
/**
* Used to shoot out css files in-line, and only once per file. Uses the CSS ID as an
* index into an array to prevent dupes.
*
* @param $handle
* @param $path
*
* @return string
*/
function cnmd_get_inline_css_file( $handle, $path ) {
if ( !isset($GLOBALS['cnmd_inline_css_record'][$handle] ) ) {
$GLOBALS['cnmd_inline_css_record'][$handle] = true;
return '<link rel="stylesheet" id="' . $handle . '" href="' . $path . '" media="all">';
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.