There is a code in here that dynamically load custom script.
<?php
function my_styles_method() {
wp_enqueue_style(
'custom-style',
get_template_directory_uri() . '/css/custom_script.css'
);
$color = get_theme_mod( 'my-custom-color' ); //E.g. #FF0000
$custom_css = "
.mycolor{
background: {$color};
}";
wp_add_inline_style( 'custom-style', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'my_styles_method' );
?>
I actually need to load only dynamic CSS part ($custom_css) and I don't need to load custom_script.css. According to this document hook like wp_print_styles is discouraged. What would be the best way to load inline style in WordPress. Maybe I am missing something.
I have rejected wp_head also from the same reason as wp_print_styles.
style.cssstylesheet from the theme? If that's the case you could attach your inline styles to it. If not, if you pass'/'towp_enqueue_styleas the second argument, the inline styles will be printed directly in the head.wp_enqueue_style( 'slug', get_stylesheet_uri() );is good solution sincestyle.cssis required in any theme. The inline styles will just follow. Would you like to add this answer @LuisSanz?