首先加载WordPress主要样式

时间:2017-02-20 17:27:38

标签: wordpress

WordPress网站在主css文件之前加载了很多东西。样式表以前在header.php文件的头部进行了硬编码,我已将其列入functions.php文件中,但是现在可以将此文件设置为优先级,以便先将其加载到其他所有文件之前?就像现在一样,它最后加载,对用户来说非常明显。

function twentyfourteen_style(){
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/css/styles.css' );
}

add_action( 'wp_enqueue_scripts', 'twentyfourteen_style' );

1 个答案:

答案 0 :(得分:2)

尝试在enqueue / register样式函数中使用依赖参数(参见https://codex.wordpress.org/Function_Reference/wp_register_style)。设置对主要样式后要加载的样式的依赖性,或者在将主样式作为依赖项加载后选择第一个样式。

编辑:或为您的操作添加优先级

add_action( 'wp_enqueue_scripts', 'twentyfourteen_style', 1 ); // added 1 as priority 1, everything else will be loaded after this action