2

I have a wordpress with a child theme where in place where is wp_head(); style.css is added like:

<link rel='stylesheet' id='parent-style-css'  href='http://something' type='text/css' media='all' />

Id like to remove this style on specific page (lets say this page has ID=5). I've found how to do this in jQuery but it seems like a bad idea to remove styles client-side.

How can I remove this style via php? possibly using https://codex.wordpress.org/Function_Reference/wp_dequeue_style but only on one specific page.

0

3 Answers 3

3

Put this code in your WP Theme Functions.php file. It should de-queue style files from specific pages:

 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'); 
    }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

How do you know what the default style sheet is called? I've tired everything and can't remove it
0

In theme functions.php you can use page id condition and put it inside it.

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

Comments

0

You can use is_page() function inside if condition to target only specific pages

is_page() function takes any one of the following as parameters

  • ID (Ex: is_page(5))
  • Page Name (Ex: is_page('Contact Us'))
  • Page Slug (Ex: 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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.