Closed bearded-avenger closed 10 years ago
Is there a better method to this than file_get_contents?
Couple of Three ideas.
<head>
and cache the request after it has been generated one time (browser should cache this as well). Generate the CSS based on theme support arguments. Purge the cached object using the after_switch_theme
hook to ensure you clean up after the plugin.I would explore option 2.
Thanks Chris! Yeah #3 gets taxing and haven't had the greatest of luck with server or client side compiling. #2 isn't a half bad idea, just hate to dirty up the head (personal preference).
Well, I'm not sure if you've seen what we do in the Worldview theme, but it involves scssphp and regenerating styles when the user changes theme options. We generate a new style.css file in the uploads directory and offer a few filters to load custom SCSS paths and inject new variables and styles that need to be compiled.
The downsides to this approach:
The upsides:
We also use this method here.
I used to do the same thing with a few themes in the past via wp-less from sancho, but the compiler was awfully slow and with too many css lines it would actually fail to compile. Had it connected to compile on the fly with customizer color change. Then had issues with ssl of course because served from a compiled http ref. I loved it when it worked, just didn't perform well enough, consistently unfortunately.
This feature is making the boat for 1.0.9 out soon.
Snip for all styles.
add_theme_support('aesop-component-styles', array( 'parallax', 'image', 'quote', 'gallery', 'content', 'video', 'audio', 'collection', 'chapter', 'document', 'character', 'map', 'timeline' ) );
Add full css styling support out of the box with add_theme_support to be used in themes. Example:
This would create css styling for the three components in the array.
Since there are 13 components there will be 13 css files.
Challenge Merge the css of the files in the array into the main style.css that's enqueued on the front end.