您可以使用wp_add_inline_style()
.
假设您将css按如下方式排队
add_action( \'wp_enqueue_scripts\', \'add_my_style\' );
function add_my_style() {
wp_enqueue_script( \'my_style\', get_template_directory_uri() . \'/mystyle.css\' );
}
然后您可以这样更改函数:
function add_my_style() {
wp_enqueue_script( \'my_style\', get_template_directory_uri() . \'/mystyle.css\' );
$style = "#mainnav li:after { content: url(\'{theme_url}/images/nav-divider.png\'); }";
$style .= "#another-example { content: url(\'{theme_url}/images/example.png\'); }";
$data = str_replace( \'{theme_url}\', get_template_directory_uri(), $style );
wp_add_inline_style( \'my_style\', $data )
}