0

I've looked at Wordpress Customizer API and it looks to be able to achieve what I'm looking for; allowing the developer to set aside as many dynamic styles which can later be configured by the Wordpress admin.

However, the recommended mechanism for injecting the styles is really not cool. All guides I've read online and from Wordpress recommend they be added inline to the Head of the document.

With the popularity of such documents flooding the net I was unable to find a definitive guide on how to add these codes neatly to a stylesheet! Can get theme mod() be called from a PHP stylesheet? Sorry please bear with me as I'm just weeks into PHP and Wordpress documentation.

Any suggestions would be nice I'm sure there are many developers who would not accept inline CSS.

1
2

However, the recommended mechanism for injecting the styles is really not cool. All guides I've read online and from Wordpress recommend they be added inline to the Head of the document.

That's how HTML works, no fault of WP's. Dynamic stylesheets have always been a challenge since CSS is not dynamic language by nature.

There is number of options, which all can be implemented relatively neatly in WordPress, however all have drawbacks.

  1. Inline styles. Bloat page source size, but just work.
  2. PHP script serving CSS. Highly flexible, but serving extra PHP script is orders of magnitude slower than serving static CSS file.
  3. Compiling and serving static CSS files. Somewhat challenging to implement (especially in code for public use), but has least performance drawbacks.

Overall the way to go depends much more on your performance requirements and how will final product be used, than specific option. There is no winning one here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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