• Why doesn’t WordPress do this by default? If you just put the CSS into a php file, you could style really easily. It would be like programming a style instead of just telling the browser exactly how everything should be styled, you can let your server do some of the work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator James Huff

    (@macmanx)

    In my opinion, having the CSS separate is better from a learner’s standpoint. There have been some themes which combine CSS in the PHP file, but the going trend is to keep the two separate. Basically, if you want to edit a certain field’s font size in sidebar.php, take a look at what class it is, and find it in style.css. This method is also recommended by most of the tutorials, Universities, training groups, etc.

    I don’t think any professional websites put the CSS styles in the html file, unless it’s to override the stylesheet.

    Putting the CSS into a .php file is actually a very easy way to implement different color schemes – make the colors PHP variables and load a set of variables for each color scheme.

    Separating CSS from HTML is the common rule “unless it’s to override the stylesheet” as fuzzy_logic stated. As HTML is dynamically generated in example with PHP, why not the same for CSS?

    The following PHP code is to provide an external CSS to any HTML page:


    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Transfer-Encoding: text");
    header("Content-Type: text/css");

    If you work with Themes like wordpress I think (imho) that you really want seperate CSS files also because there are so many places of putting your different layout classes / ID’s etc.etc.

    Besides that if you want PHP-CSS I don’t see the real use of it, just makes things more complicated for people who do not understand PHP.

    When a file is named .php people already are scared of it contents…

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Why not put CSS into .php’ is closed to new replies.