2016-07-28 186 views
0

我有一个WordPress主题,其中wp_head(); style.css增加,如:如何删除特定wordpress页面上的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,但只能在一个特定页面上使用。

回答

1

将这个代码在你的WP主题功能。 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'); 
    } 
} 
0

在主题functions.php你可以使用页面ID条件,并把它放在里面。

global $post; 
if($post->ID == '20'){ 
     // dequeue code here 
    } 
0

可以使用is_page()函数内部if条件仅定位

is_page()功能的特定网页采用以下中的任何一个作为参数

  • ID(例如: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 
}