我有一个问题,我已经能够使用以下代码在我的 wordpress 主题部分中包含自定义 css:
function load_my_style_wp_enqueue_scripts()
{
wp_register_style('my_styles_css', includes_url("/css/my_styles.css"));
wp_enqueue_style('my_styles_css');
}
add_action('wp_enqueue_scripts','load_my_style_wp_enqueue_scripts');
但是源码中的顺序是这样的:
<link rel='stylesheet' id='my_styles_css-css' href='http://...folderA.../my_styles.css?ver=3.1' type='text/css' media='all' />
<link rel="stylesheet" id="default-css" href="http://...folderB.../default.css" type="text/css" media="screen,projection" />
<link rel="stylesheet" id="user-css" href="http://...folderC.../user.css" type="text/css" media="screen,projection" />
我希望 my_styles_css 成为最后加载的文件,覆盖默认文件和用户文件。我试图通过以不同方式修改 wp_enqueue_style 来实现这一点,但没有成功。我试过:
wp_enqueue_style('my_styles_css', array('default','user'));
或
wp_enqueue_style('my_styles_css', false, array('default','user'), '1.0', 'all');
我看到一些相关问题没有答案,或者最后两种方法对我来说仍然失败。
上述功能是我在 wordpress 安装中启用的插件的一部分。
最佳答案
add_action 函数有一个优先级参数,可能有助于:
$priority (int) (optional) How important your function is. Alter this to make your function be called before or after other functions. The default is 10, so (for example) setting it to 5 would make it run earlier and setting it to 12 would make it run later. Default: 10
http://codex.wordpress.org/Function_Reference/add_action
或者您可以直接链接到您的 header.php 文件中的 css,而不是使用 wp_enqueue_style,因此将它准确地放置在您想要的位置。
关于css - Wordpress:如何覆盖所有默认主题 CSS,以便最后加载您的自定义主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8904379/