Use of PHP in CSS vs Adaption via JS[General]

I have a general question about the use of PHP in CSS.
I am working right now on a WordPress Theme and would like to make it as customizable as possible.
I therefore sent the CSS Properties I would like to change via PHP to a JS file that changed them for me.
But I am unsure if this is the best way to do it.

Would you guys recommend it and what are the pros and cons?

Related posts

Leave a Reply

2 comments

  1. Let me tell you how I implemented customisable themes on my website, and see if it’s of any help to you.

    To start with, I use LESS. Wherever I have something customisable (usually colours, but sometimes background images too) I drop in a variable.

    Then I have a _colours.less file, which simply defines all the variables, and gets imported at the start of every other .less file.

    Finally, I present the users with an interface to edit these variables in a user-friendly manner.

    At run-time, the PHP checks:

    • Does the main core.css file exist?
    • Is the core.css‘s modification time more recent than the _colours.less modification time?
    • Are the modification times of all .css file being used in this page more recent than the corresponding .less file’s?

    If any of the above result in the answer “no”, then the given .css file is recompiled on-the-fly using the PHP lessc class (that basically implements the LESS compiler).

    In this way, users can easily create their own custom themes, but it doesn’t interfere in any way with my ability to update the site’s layout.

  2. sending php value in js may create trouble sometime.

    suppose your user install some plugin which js may conflict with your theme’s js.
    It is possible it stops parsing further js and your changes may not apply.

    So according to me setting php value in css is good method.