首页 文章

如何删除特定wordpress页面上的style.css

提问于
浏览
1

我有一个带有子主题的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但仅限于一个特定页面 .

3 回答

  • 0

    将此代码放在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'); 
        }
     }
    
  • 2

    在主题 functions.php 中,您可以使用页面ID条件并将其放入其中 .

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

    您可以在 if 条件内使用 is_page() 函数来仅定位特定页面

    is_page() 函数将以下任何一项作为参数

    • ID (例如: is_page(5)

    • Page Name (例如: is_page('Contact Us')

    • Page Slug (例如: is_page('contact-us')

    Examples

    if(is_page(5)){
    // wp_dequeue_style
    }
    
    
    if(is_page('Contact us')){
    // wp_dequeue_style
    }
    
    
    if(is_page('contact-us')){
    // wp_dequeue_style
    }
    

相关问题