Skip to content

Instantly share code, notes, and snippets.

@derekshirk
Created June 27, 2014 16:41
Show Gist options
  • Save derekshirk/bc676706d332573fcb51 to your computer and use it in GitHub Desktop.
Save derekshirk/bc676706d332573fcb51 to your computer and use it in GitHub Desktop.
WordPress - Enqueueing Inline CSS
<?php
$custom_style_file = get_template_directory_uri() . '/css/custom_style.css';
function custom_styles() {
wp_enqueue_style( 'custom-style', $custom_style_file );
$headline_font_weight = get_theme_mod( 'headline-font-weight' );
$custom_style = '.headline { font-weight: ' . $headline_font_weight . '; }';
wp_add_inline_style( 'custom-inline-style', $custom_style );
}
add_action( 'wp_enqueue_scripts', 'custom_styles' );
?>
@derekshirk
Copy link
Author

Ever needed to include a variable, inline style for your plugin or theme? Of course you did! Enqueueing external CSS files with WordPress' wp_enqueue_style() function (and its companions) is pretty slick but it lacks the functionality to include inline CSS styles.

Well, at least that's what I thought before coming across the wp_add_inline_style() function.

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