您不应该在wp_enqueue_scripts
胡克,正在排队。将css输出移动到连接到的函数wp_head
优先级低于8,这是列队样式打印时的优先级wp_head
:
function folio_enqueue_css() {
wp_enqueue_style( \'theme\', get_template_directory_uri() . \'/assets/css/style.css\', false, \'1.0\', \'all\' );
}
add_action( \'wp_enqueue_scripts\', \'folio_enqueue_css\', 1 );
function folio_dynamic_css() {
ob_start();
echo \'<style type="text/css">\';
# css styles here
echo \'</style>\';
# compress CSS
$output = ob_get_clean();
echo preg_replace(\'/^\\s+|\\n|\\r|\\s+$/m\', \'\', $output) ."\\n";
}
add_action( \'wp_head\', \'folio_dynamic_css\', 20 );