Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have one stylesheet linked to my Wordpress page in header section:

<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style.css" />

Now, I want to load different stylesheets on a few pages or sub-pages.

What's the best/correct way of achieving this?

I'm thinking about writing my own shortcode calling "wp_enqueue_style", is that a good idea?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Don't use a shortcode for wp_enqueue_style(); it won't do any good, because by the time the shortcode is parsed, all the relevant hooks ( wp_head, wp_print_styles) will have already fired.

Write a function, in functions.php, to enqueue different style sheets based on is_page( $id ) (where $id can be an ID, slug, or title). Then hook that function into wp_enqueue_scripts.

p.s. note also: you should be using get_stylesheet_uri() in your default stylesheet link, e.g.:

<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>/style.css" />
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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