Skip to content

Instantly share code, notes, and snippets.

@anastis
Created March 7, 2017 22:27
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 anastis/205aa7531a61a50a304646bd5e26087e to your computer and use it in GitHub Desktop.
Save anastis/205aa7531a61a50a304646bd5e26087e to your computer and use it in GitHub Desktop.
Inlining styles in WordPress without an actual CSS file
<?php
add_action( 'some_hook', 'maxslider_enqueue_slider_css' );
function maxslider_enqueue_slider_css() {
$css = '';
// ...
if ( true === $something ) {
$css = 'body { background-color: ' . $color . '; }';
}
// ...
wp_register_style( 'maxslider-footer', false );
wp_enqueue_style( 'maxslider-footer' );
wp_add_inline_style( 'maxslider-footer', $css );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment