Skip to content

Instantly share code, notes, and snippets.

@theMikeD
Created June 16, 2017 17:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theMikeD/f002f696f365aff7c8252f6365cc7d5e to your computer and use it in GitHub Desktop.
Save theMikeD/f002f696f365aff7c8252f6365cc7d5e to your computer and use it in GitHub Desktop.
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