Reputation: 847
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.
Upvotes: 2
Views: 12345
Reputation: 837
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');
}
}
Upvotes: 3
Reputation: 707
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
is_page(5)
)is_page('Contact Us')
)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
}
Upvotes: 0
Reputation: 1196
In theme functions.php you can use page id condition and put it inside it.
global $post;
if($post->ID == '20'){
// dequeue code here
}
Upvotes: 0