[英]How to remove style.css on specific wordpress page
我有一個帶有兒童主題的wordpress,其中wp_head()在哪里? style.css
添加如下:
<link rel='stylesheet' id='parent-style-css' href='http://something' type='text/css' media='all' />
我想在特定頁面上刪除此樣式(假設此頁面的ID為5)。 我已經找到了如何在jQuery中執行此操作,但是刪除客戶端樣式似乎是一個壞主意。
如何通過php刪除此樣式? 可能使用https://codex.wordpress.org/Function_Reference/wp_dequeue_style,但僅在一個特定頁面上使用。
將此代碼放在WP Theme Functions.php文件中。 它應該從特定頁面出隊樣式文件:
add_action('init','_remove_style');
function _remove_style(){
global $post;
$pageID = array('20','30', '420');//Mention the page id where you do not wish to include that script
if(in_array($post->ID, $pageID)) {
wp_dequeue_style('style.css');
}
}
在主題functions.php中,您可以使用頁面ID條件並將其放在其中。
global $post;
if($post->ID == '20'){
// dequeue code here
}
if
條件僅定位到特定頁面, if
可以在內部使用is_page()
函數
is_page()
函數采用以下任意一項作為參數
is_page(5)
) is_page('Contact Us')
) is_page('contact-us')
) 例子
if(is_page(5)){
// wp_dequeue_style
}
if(is_page('Contact us')){
// wp_dequeue_style
}
if(is_page('contact-us')){
// wp_dequeue_style
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.