我有一个带有子主题的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但仅限于一个特定页面。
答案 0 :(得分:2)
将此代码放入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');
}
}
答案 1 :(得分:0)
在主题 functions.php 中,您可以使用页面ID条件并将其放入其中。
global $post;
if($post->ID == '20'){
// dequeue code here
}
答案 2 :(得分:0)
您可以在is_page()
条件中使用if
功能仅定位特定页面
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
}