Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Isaac Russell
Isaac Russell
12,091 Points

How can I apply different stylesheets to different page templates?

I'm creating a theme from the bootstrap framework into a wordpress site. I have linked the stylesheets via the functions.php using the wp_enqueue_scripts as follows:

function theme_styles() { wp_enqueue_style( 'my-style-blog', get_template_directory_uri() . '/css/my-style-blog.css' ); wp_enqueue_style( 'projects', get_template_directory_uri() . '/css/projects.css' ); wp_enqueue_style( 'main', get_template_directory_uri() . '/css/style.css' ); wp_enqueue_style( 'my-styles', get_template_directory_uri() . '/css/my-styles.css' ); }

but the links follow the typical css cascade.

How can I apply different stylesheets to different pages?

Ex. (1) front-page.php has it's own "front-page.css" styles. (2) page.php has it's own "page.css" style.

In other words I want the majority of the styles to be able to be used across the entire site, but some pages to display differently. For example in my homepage I have a large responsive image in the header I have included by css that I don't want to show on other pages. This is included by use of the

wp_enqueue_style( 'my-styles', get_template_directory_uri() . '/css/my-styles.css' );

}

Please advise

1 Answer

missgeekbunny
missgeekbunny
37,033 Points

the way that I did it on bunnieblogs.com is I target the stylesheet for different pages. So like on my shop page I say ```if( is_page('shop')) { wp_enqueue_style('green', get_stylesheet_directory_uri() . 'green.css'); }

Hope that helps.
To target the page specifically you just need to call it by the name you put in the link below the title. So like for instance the above is bunnieblogs.com/shop/.  And if that doesn't make sense just check out http://codex.wordpress.org/Conditional_Tags