This question already has answers here: How do I load custom scripts and styles for a page? (2 answers) Closed 5 years ago.admin管理员组文章数量:1428611
Is it possible to assign a css stylesheet to specific pages only?
If so how?
Can I use something like this? Not sure how to specify the pages though?
add_action( 'wp_enqueue_scripts', 'enqueue_theme_css' );
function enqueue_theme_css()
{
wp_enqueue_style(
'default',
get_template_directory_uri() . '/css/default.css'
);
}
This question already has answers here:
How do I load custom scripts and styles for a page?
(2 answers)
Closed 5 years ago.
Is it possible to assign a css stylesheet to specific pages only?
If so how?
Can I use something like this? Not sure how to specify the pages though?
add_action( 'wp_enqueue_scripts', 'enqueue_theme_css' );
function enqueue_theme_css()
{
wp_enqueue_style(
'default',
get_template_directory_uri() . '/css/default.css'
);
}
Share
Improve this question
edited May 31, 2019 at 14:44
Johansson
15.4k11 gold badges43 silver badges79 bronze badges
asked May 31, 2019 at 14:42
Gavin ReynoldsonGavin Reynoldson
1054 bronze badges
0
1 Answer
Reset to default 0Yes, it is possible. All you need to do is to check whether you are on a specific page or not. For example, this will enqueue your scripts only for the page that has the contact-us
slug:
add_action( 'wp_enqueue_scripts', 'enqueue_theme_css' );
function enqueue_theme_css()
{
if( is_page( 'contact-us' ) ){
wp_enqueue_style(
'default',
get_template_directory_uri() . '/css/default.css'
);
}
}
You can take a look into the is_page()
function for more informations.
本文标签: wp enqueue styleSet different css stylesheet for specific pages
版权声明:本文标题:wp enqueue style - Set different css stylesheet for specific pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745447490a2658730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论