我有一个notmytheme, 最初的css加载顺序如下:
<link rel=\'stylesheet\' id=\'something\' href=\'http://localhost/mywp/wp-content/themes/notmytheme/something.css\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'notmytheme-style-css\' href=\'http://localhost/mywp/wp-content/themes/notmytheme/style.css?ver=1.0.9\' type=\'text/css\' media=\'all\' />
当我创建一个名为notmytheme-child, 然后把孩子们排成一列,变成这样:<link rel=\'stylesheet\' id=\'notmytheme-style-css\' href=\'http://localhost/mywp/wp-content/themes/notmytheme/style.css?ver=1.0.9\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'child-style-css\' href=\'http://localhost/mywp/wp-content/themes/notmytheme-child/style.css?ver=18.08.07\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'something\' href=\'http://localhost/mywp/wp-content/themes/notmytheme/something.css\' type=\'text/css\' media=\'all\' />
我希望父样式和子样式在其他样式之后加载,例如父主题的加载方式,因此我将其按优先级向下移动(add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\', 999 );
), 现在变成这样:<link rel=\'stylesheet\' id=\'something\' href=\'http://localhost/mywp/wp-content/themes/notmytheme/something.css\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'notmytheme-style-css\' href=\'http://localhost/mywp/wp-content/themes/notmytheme-child/style.css?ver=1.0.9\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'child-style-css\' href=\'http://localhost/mywp/wp-content/themes/notmytheme-child/style.css?ver=18.08.07\' type=\'text/css\' media=\'all\' />
我不知道为什么,但现在get_template_directory_uri()
现在指向notmytheme-child 而不是notmytheme.我当前的排队脚本如下所示:
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\', 999 );
function my_theme_enqueue_styles() {
$parent_style = \'notmytheme-style\';
wp_enqueue_style( $parent_style,
get_template_directory_uri() . \'/style.css\',
array(),
\'1.0.9\' );
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri() . \'/style.css\',
array( $parent_style ),
\'18.08.07\',
\'all\' );
}
调整优先级会更改css的加载位置以及哪个目录get_template_directory_uri()
指向。EDIT/SOLUTION
我的代码现在是:add_action( \'wp_enqueue_scripts\', \'my_enqueue_child\', 999 );
function my_enqueue_child() {
wp_dequeue_style( \'notmytheme-style\' );
wp_enqueue_style( \'parent-style\',
get_template_directory_uri() . \'/style.css\',
array(),
\'1.0.9\' );
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri() . \'/style.css\',
array( \'parent-style\' ),
\'18.08.07\',
\'all\' );
}