0

I am trying to use different stylesheets for different pages, but it doesnt kinda work. For example i made a page called 'Contact' and assigned the template contact-template.php to it.

and this is how i enqueued my stylesheets:

if(!is_admin()){
    if(is_front_page()){
        wp_enqueue_style('front-page-style', get_template_directory_uri() . '/style.css');
    }
    else if(is_page('contact-template.php')){
        wp_enqueue_style('page-style', get_template_directory_uri() . '/style-contact.css');
    }
    else{
        wp_enqueue_style('default-style', get_template_directory_uri() . '/style-default.css');
    }
}

i already tryed using is_page_template('contact-template.php'); but not working...

1 Answer 1

0

Instead of:

is_page('contact-template.php')

Try:

is_page('contact')

is_page expects a post ID or slug.

If instead you want to enqueue this CSS for any page using this template, put the enqueueing PHP into the template itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.