css - Wordpress:如何覆盖所有默认主题 CSS,以便最后加载您的自定义主题?

标签 css wordpress

我有一个问题,我已经能够使用以下代码在我的 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,因此将它准确地放置在您想要的位置。

否则这里好像有答案:How to force wp_enqueue_style to display CSS at the very bottom of the head tag to override all CSS rules?

关于css - Wordpress:如何覆盖所有默认主题 CSS,以便最后加载您的自定义主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8904379/

相关文章:

javascript - 在 WordPress 存档循环中添加 Owl Carousel 而不是帖子缩略图

wordpress - Openshift Wordpress 中自定义域的 SSL 证书错误

jquery - css 或 jquery 中的圆形停靠栏/菜单

javascript - Jquery window.scrollTo 导致页面卡住

html - Div 没有向左浮动

regex - WordPress 重定向插件不区分大小写的正则表达式

Javascript each() 函数删除链接

javascript - 图像宽度 CSS 问题

html - Isotope + Wordpress 排版模式

html - CSS 未在 WordPress 中更新