Grow your CSS skills. Land your dream job.

PHP variables in CSS not working!

  • # December 22, 2012 at 8:41 am

    I am running a wordpress site [here](http://bochdewi.co.uk/htmlmainia) and im trying to run php in the style.css with .htaccess but its not working.

    # December 22, 2012 at 8:45 am

    Working link: http://bochdewi.co.uk/htmlmainia/

    # December 22, 2012 at 8:46 am

    oops sory for that.

    # December 22, 2012 at 9:04 am

    @htmlmainiac Can we see your style.css file?

    Edit: Oops. I meant your .htaccess file.

    It seems it’s working since I see styling on your site. What’s not working for you?

    # December 22, 2012 at 9:20 am

    Try adding this piece of code in place of yours at the top of your style.css file.

    < ?php
    header(“Content-type: text/css; charset: UTF-8″);

    $noUnderline = “none”;
    ?>

    And then right outside the closing PHP tag (?>), place this:

    a {text-decoration: < ?php echo $noUnderline; ?>;}

    # December 23, 2012 at 1:34 pm

    It’s style.css because that is what I need for WordPress but the code is not running.

    # December 23, 2012 at 1:35 pm

    Just look at it there is php at the top

    # December 23, 2012 at 1:38 pm

    I don’t see any PHP. PHP shouldn’t output as PHP unless there’s an error in your code. Is the htaccess file in the same place as your style.css?

    # December 23, 2012 at 2:05 pm

    I’ve found a couple ways to do this. You can either tell your server to rewrite a *.css request to look at a PHP script (such as “style.php?name=style”). The other way you can do this is by configuring .css files to be handled by php. I think this .htaccess code should work:


    php_value default_mimetype "text/css"

    Make sure this .htaccess is at least in the same directory as your css php script.

    # December 24, 2012 at 7:16 am

    @DustinWoods The problem is that i run wordpress so it cant be style.php it has to be style.css and i used the code from Chris on this site but it didnt work.

    # December 24, 2012 at 8:14 am

    @Htmlmainiac Can you at least answer our questions while ignoring some of our solutions?

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".