Parsing PHP in CSS

Wednesday, October 1, 2008

Pro-Tip: Tell your website to treat CSS files as if they’re PHP files to make life easier.

There are only two simple things you need to do to enable this!

  1. Add this to your .htaccess file:
    AddHandler application/x-httpd-php .css

  2. Add this — inside <?php & ?> brackets — to the very beginning of your CSS file(s):
    header(’Content-type: text/css’);

That’s really all there is to it.

Now you can use variables (and any other PHP) in your CSS files. Life is good.

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>