2010-11-18 25 views
7

我目前正在研究如何創建通過插件WordPress管理模板,並根據Wordpress Wiki,您可以使用掛鉤,例如admin_headwp_admin_css,和/或login_head手動呼應你的鏈接的HTML標籤:如何強制wp_enqueue_style在head標籤的最底部顯示CSS以覆蓋所有CSS規則?

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

的例子顯然是壞事,因爲鏈接標記PHP邏輯中硬編碼的方式。

理想的是使用wp_enqueue_style()來插入CSS。然而,它有自己的想法 CSS插入,並只對它喜歡的鉤子作出反應。例如,wp_enqueue樣式在admin_head內沒有反應良好。到目前爲止,我只能用這裏面wp_print_styles初始化,但話又說回來,你真的不能顯示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' /> 

我只想pinq - 管理 - css顯示在頭標記的岩石底部(最好在關閉頭之前),以便它可以覆蓋所有已加載的與Wordpress相關的CSS。

對此有何看法?

回答

7

嘿。 wp_enqueue_style有一個叫$deps的論點,你應該試試看。你可能會提到你的樣式表依賴於其他所有的樣式表,因此把它放在其他的下面。除此之外,您還可以繼續使用!important。更多信息依賴關係:http://codex.wordpress.org/Function_Reference/wp_enqueue_style

+3

wp_enqueue_style(「pinq管理員」,get_bloginfo( 'stylesheet_directory')。「/css/pinq-admin.css」,數組('顏色','thickbox'))的伎倆。它在thickbox-css和colors-css之下。巧妙。謝謝! – 2010-11-22 03:47:26

+0

您也可以使用這種技術,通過將$ deps設置爲數組('%theme_name%-style')來確保排隊後的css在站點style.css之後出現 – Snaver 2014-04-04 12:09:28

0

我知道這是古老的,但這裏有一些實際的代碼,從我的網站剪切和粘貼。這是我的孩子主題的functions.php文件:

add_action('init', 'add_custom_styles', 99); 
function add_custom_styles() { 
wp_enqueue_style('custom-styles', get_stylesheet_directory_uri() .'/custom.css', array('storefront-style', 
'wc-bundle-style','storefront-child-style')); 
} 

的「自定義樣式」僅僅是其中包含了我希望我所有的自定義樣式的子主題目錄名爲文件「custom.css」最後加載。

另外,找到你想成爲你的custom.css樣式表,上面的樣式表的手柄,使用的技術這裏概述:

http://crunchify.com/how-to-print-all-loaded-java-scripts-and-css-stylesheets-handle-for-your-wordpress-blog/