Created
June 27, 2014 16:41
-
-
Save derekshirk/bc676706d332573fcb51 to your computer and use it in GitHub Desktop.
WordPress - Enqueueing Inline CSS
This file contains 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
<?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' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.