How to work with custom styles saved in theme option?

When your users really need 30 lines of custom CSS, your theme is flawed. Create a set of predefined styles instead (dark and light scheme, sans and serif fonts etc.) and prepare your main stylesheet for these cases. You can hook into body_class then and add the classes you need to get these styles.
Adjustments for your users should be very minimal then.

Using an endpoint for a PHP generated stylesheet is something like your second option. That’s not a problem in IE, and a caching plugin will help reducing the processing time further. I would use the timestamp of the last change for the endpoint, eg.:

example.com/css/012345678/

… to make sure the browser fetches the freshest stylesheet and caches the file as it should.

Option 3 means: you have to save the file per Filesystem API, you have to make sure it isn’t deleted later (tricky!), and you should replace the old file to avoid insane amounts of CSS files. Forcing the new file to replace the cached file without an additional GET parameter isn’t easy too.

Use an endpoint.

Leave a Comment