The easiest way to add dynamic CSS is to put it inside a callback and hook the callback into the template, e.g. via wp_head
(or wp_print_styles
).
You’ve not posted your code in full context, so you will need to modify to suit your specific needs. That said, here’s the basic principle:
Callback
function wpse_129259_enqueue_dynamic_css() {
// Grab your variable
global $data;
?>
<style type="text/css">
a {
color:<?php echo $data['link_color'];?>;
}
</style>
<?php
}
Hook
add_action( 'wp_head', 'wpse_129259_enqueue_dynamic_css' );
Using style.php
You can put your dynamic CSS in its own PHP file, then simply include it inside your callback. e.g.:
function wpse_129259_enqueue_dynamic_css() {
// Include dynamic CSS file
include( get_template_directory() . '/style.php' );
}
add_action( 'wp_head', 'wpse_129259_enqueue_dynamic_css' );