0

This question already has an answer here:

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'
    );
}

marked as duplicate by Community May 31 at 15:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Yes, 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.

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