如何强制 wp_enqueue_style 在 head 标签的最底部显示 CSS 以覆盖所有 CSS 规则? [英] How to force wp_enqueue_style to display CSS at the very bottom of the head tag to override all CSS rules?

查看:24
本文介绍了如何强制 wp_enqueue_style 在 head 标签的最底部显示 CSS 以覆盖所有 CSS 规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究如何通过插件创建 Wordpress 管理模板,并根据 Wordpress Wiki 您可以使用诸如 admin_headwp_admin_css 和/或 login_head 之类的钩子来手动回显您的链接 html 标记:

I am currently studying on how to create Wordpress administration templates via plug-ins, and according to the Wordpress Wiki you can use hooks such as admin_head, wp_admin_css, and/or login_head to manually echo your link html tag:

echo "<link rel="stylesheet" type="text/css" href="' . get_option('siteurl') . '/wp-content/plugins/blue-steel/login.css" />'."\n";

这个例子显然是坏事,因为链接标签在 php 逻辑中是硬编码的.

The example obviously is A Bad Thing because of the way the link tag is hardcoded inside php logic.

理想的是使用 wp_enqueue_style() 插入 CSS.但是,它有自己的WHEN 插入 CSS 的想法,并且只对它喜欢的钩子做出反应.例如,wp_enqueue 样式在 admin_head 中的响应不佳.到目前为止,我只能在 wp_print_stylesinit 中使用它,但是在所有默认 CSS 加载后,您又无法真正显示 CSS:

The ideal is to use wp_enqueue_style() to insert CSS. However, it has it's own idea of WHEN the CSS is inserted, and only reacts to the hooks it likes. For example, wp_enqueue style doesn't respond well inside admin_head. So far I can only use it inside wp_print_styles and init, but then again you can't really display the CSS after all the default CSS has loaded:

<link rel='stylesheet' href='http://localhost/wordpress/wp-admin/load-styles.php?c=0&amp;dir=ltr&amp;load=plugin-install,global,wp-admin&amp;ver=9e478aac7934ae559830ecb557b6511d' type='text/css' media='all' />
<link rel='stylesheet' id='pinq-admin-css'  href='http://localhost/wordpress/wp-content/themes/ardee/css/pinq-admin.css?ver=3.0.1' type='text/css' media='all' />
<link rel='stylesheet' id='thickbox-css'  href='http://localhost/wordpress/wp-includes/js/thickbox/thickbox.css?ver=20090514' type='text/css' media='all' />
<link rel='stylesheet' id='colors-css'  href='http://localhost/wordpress/wp-admin/css/colors-fresh.css?ver=20100610' type='text/css' media='all' />

我只希望 pinq-admin-css 显示在 head 标签的底部(最好在关闭 head 之前),以便它可以覆盖所有与 Wordpress 相关的 CSS已加载.

I just want pinq-admin-css to display at the rock-bottom of the head tag (preferably just before the closing head) so that it can override all Wordpress-related CSS that has been loaded.

对此有什么想法吗?

推荐答案

嘿.wp_enqueue_style 有一个名为 $deps 的参数,你应该试一试.您可能会提到您的样式表依赖于所有其他样式表,因此将其置于其他样式表之下.除此之外,您还可以继续使用 !important.有关依赖项的更多信息:http://codex.wordpress.org/Function_Reference/wp_enqueue_style

Hey. There's an argument called $deps for wp_enqueue_style, you should give it a try. You might be able to mention that your stylesheet depends on all the rest, thus putting it below the others. Other than that, you can also go ahead with !important. More info on dependencies: http://codex.wordpress.org/Function_Reference/wp_enqueue_style

这篇关于如何强制 wp_enqueue_style 在 head 标签的最底部显示 CSS 以覆盖所有 CSS 规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆