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.