I haven’t clarified what is the best method to apply styles from the customizer. However, this is the function i am using right now (Not using the previous one anymore, therefore, you can remove the wp_add_inline_style part):
// I like this way so much more that i'm going to cry.
// Thanks to:
// https://code.tutsplus.com/tutorials/settings-and-controls-for-a-color-scheme-in-the-theme-customizer--cms-21350
// https://code.tutsplus.com/tutorials/adding-the-css-for-a-color-scheme-in-the-theme-customizer--cms-21351
function theme_customizer_styles()
{
$textColor = get_theme_mod('text_color');
$linkColor = get_theme_mod('link_color');
$headerNavigationBackgroundColor = get_theme_mod('header_navigation_background_color');
$headerNavigationLinkColor = get_theme_mod('header_navigation_link_color');
ob_start();
?>
<style>
body {
color: <?php echo $textColor; ?>;
}
a {
color: <?php echo $linkColor; ?>;
}
.navigation {
background-color: <?php echo $headerNavigationBackgroundColor; ?>;
}
.menu-item a {
color: <?php echo $headerNavigationLinkColor; ?>;
}
</style>
<?php
ob_flush();
}
add_action('wp_head', 'theme_customizer_styles');
There is a lot of room for improvement of course, please feel free to add on this approach, or to provide us with a better one, or your preferred one.