Isn’t one always better?
No. If you are thinking of creating a page-specific CSS file and somehow concatenating the parts it needs into that single file, don’t. It seems like, hey, one request is better than three! But then you aren’t leveraging the browser cache at all.
http://www.hanselman.com/blog/TheImportanceAndEaseOfMinifyingYourCSSAndJavaScriptAndOptimizingPNGsForYourBlogOrWebsite.aspx
One, Two, or Three
But I will like to know your own practical experiences. Thanks.
@rosyteddy a couple of good reads there man, i like to read through the comment sections on articles like the ones above because there is some good points raised, there are alot of varied opinions as how to effectively pull this off dependent on the complexity of your site, which i would consider mine as quite complex, the reason for the questions and advice is because of how complex i consider the website to be, i have alot of stylesheets for various different things here there and everywhere loading when not needed etc, in the past i have used plugins to successfully combine and serve them as one cached minified version etc.. but i was just wanting to go more in depth with it and configure it all myself to run at an optimum level.
I am going to be messing around with this over the next few days and will get back to you on what i feel was the best way to do it, any more advice off anyone else who has tackled doing this manually for wordpress/buddypress give us a shout.
Hey @mcpeanut,
There’s no right and wrong way but this is what I do:
Put all of your global CSS properties into style.css. for example, styles that related to your header, footer and main templates and then conditionally enqueue stylesheets that are used less regularly so that they’re only loaded when absolutely necessary.
@henrywright cheers henry any little info and suggestions how others do it always helps, i know that it mainly boils down to each specific website how this is done in the best possible way, and alot of it can depend on how many stylesheets various plugins load, i wish more developers would give you an option in the backend to use your own stylesheets as standard and let you just turn them off from loading, i know more and more plugins are giving you this option but there are alot that still don’t, i like to customize everything myself and would rather not have to dequeue these stylesheets manually. its quite annoying.
You can dequeue style sheets with wp_dequeue_style()
. You just need to find the handle used when the style sheet you want to remove is enqueued. Something like this:
$handle = 'something-here';
wp_dequeue_style( $handle );
You probably know that though but I thought I’d post in case anyone else might be wondering how it’s done.
yes that’s how ive been doing it henry, but cheers its a good idea like you said to post the code so others know what we are talking about lol
you can also use something like this
add_action( 'wp_enqueue_scripts', 'remove_default_stylesheet', 20 );
function remove_default_stylesheet() {
wp_dequeue_style( 'original-enqueue-stylesheet-handle' );
wp_deregister_style( 'original-register-stylesheet-handle' );
wp_register_style( 'new-style', get_stylesheet_directory_uri() . '/new.css', false,'1.0.0' );
wp_enqueue_style( 'new-style' );
}
This way you can first dequeue/deregister styles you dont want and then register/enqueue the new stylesheets