如何强制wp_enqueue_style在head标签的最底部显示CSS以覆盖所有CSS规则?

Ard*_*ram 7 wordpress wordpress-theming wordpress-plugin

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

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

这个例子显然是A Bad Thing,因为链接标记在php逻辑中是硬编码的.

理想的是使用wp_enqueue_style()来插入CSS.但是,它有它自己的想法WHEN的CSS插入,只有反应它喜欢的挂钩.例如,wp_enqueue样式在admin_head内部响应不佳.到目前为止,我只能在wp_print_stylesinit中使用它,但是在所有默认CSS加载后你再也无法真正显示CSS:

<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' />
Run Code Online (Sandbox Code Playgroud)

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

有什么想法吗?

kov*_*nin 7

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

  • wp_enqueue_style('pinq-admin',get_bloginfo('stylesheet_directory')."/ css/pinq-admin.css",array('colors','thickbox'))就可以了.它低于thickbox-css和colors-css.巧妙.谢谢! (3认同)