Skip to:
Content
Pages
Categories
Search
Top
Bottom

<?php $_SERVER['REQUEST_URI'] ?> in css


  • csseur3
    Member

    @csseur3

    Hello,

    i want to add in my css an image of the /wp-content folder of my blog, like:

    background: url(“<?php $_SERVER ?>/wp-content/themes/default/images/background.gif”) repeat-x top;

    but doesn’t work. why ?

    bye,

    Fred

Viewing 2 replies - 1 through 2 (of 2 total)

  • _ck_
    Participant

    @_ck_

    I think you asked this on the IRC channel but I will also answer here to help others.

    PHP is not processed in style.css (unless you force your server to, and that’s not recommended)

    However you can edit your theme’s header.php and create an additional “inline” stylesheet like so:

    <style>
    body {background: url("<?php echo $_SERVER['REQUEST_URI']; ?>/wp-content/themes/default/images/background.gif") repeat-x top;}
    </style>
    </head>

    (note that </head> at the end, it’s meant to indicate you should put that code at the end of the <head></head> section)

    Also, more importantly, $_SERVER['REQUEST_URI'] is not going to be the variable you want. Probably more like $_SERVER['DOCUMENT_ROOT'] and you’ll have to add the path to wordpress too.

    Actually thats not true. I’ve done this several times and in the PHPulse MVC Framework use this trick.

    If you declare your CSS as ‘file.css.php’ rather than ‘file.css’, the file will be parsed as PHP and output to be read as CSS. Since the webserver handles the request for the CSS request, it sees the file extension and parses it a PHP. But the browser expects back a CSS page (as you declared it within the header as type ‘text/css’).

    This is convenient as it enables you to import PHP settings into your CSS sheets such as defines to set colors, fonts, sizes, etc across all style sheets. This enables to to easily create and change themes without changing a million lines in your CSS.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.