Php 如何删除特定wordpress页面上的style.css
我有一个带有子主题的wordpress,其中wp_head()在哪里<代码>样式。添加css如下:Php 如何删除特定wordpress页面上的style.css,php,wordpress,Php,Wordpress,我有一个带有子主题的wordpress,其中wp_head()在哪里样式。添加css如下: <link rel='stylesheet' id='parent-style-css' href='http://something' type='text/css' media='all' /> 我想删除特定页面上的此样式(假设此页面的Id=5)。 我已经在jQuery中找到了如何做到这一点,但在客户端删除样式似乎不是一个好主意 如何通过php删除此样式?可能使用,但只能在一个特定
<link rel='stylesheet' id='parent-style-css' href='http://something' type='text/css' media='all' />
我想删除特定页面上的此样式(假设此页面的Id=5)。
我已经在jQuery中找到了如何做到这一点,但在客户端删除样式似乎不是一个好主意
如何通过php删除此样式?可能使用,但只能在一个特定页面上使用。在主题函数中。php您可以使用页面id条件并将其放入其中
global $post;
if($post->ID == '20'){
// dequeue code here
}
如果条件仅针对特定页面,则可以使用中的is_page()
函数
is\u page()
函数将以下任意一项作为参数
- ID(例如:
是第(5)页
)
- 页面名称(例如:
是页面(“联系我们”)
)
- 页面Slug(例如:
是页面('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
}
将此代码放在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');
}
}
您如何知道默认样式表的名称?我什么都累了,搬不动了