Lets say you are implementing a color picker in wordpress options page, but you want to dynamically change colors or background for your header, menu or a link. Here is how to do it correctly and its unbelievably simple in wordpress. Just add a hook to wp_head and look at the code snippet below.
function my_custom_styles() { $softlights_options = get_option('my-theme-options'); echo "<style>nav ul li a { color:". $menu-font-color ." !important }</style>"; echo '<style>nav {background:'.$menu-color .'}</style>'; echo '<style>#header {background:'.$header-color .'}</style>'; } add_action('wp_head','my_custom_styles');
But if you want to add a separate stylesheet dynamically you might want to use wp_enqueue_style() function.
function my_custom_styles() { $softlights_options = get_option('my-theme-options'); wp_enqueue_style( 'default', get_stylesheet_uri() ); // add default stylesheet style.css wp_enqueue_style('custom', get_template_directory_uri().'/css/blue.css'); } add_action('wp_head','my_custom_styles');