I am carrying out a style.php CSS file in order to apply certain dynamic variables within the CSS inside a Wordpress installation:

<?php header("Content-type: text/css"); ?>

and so forth.

How do i access a worldwide variable from inside the design and style.perl file or pass a flexible into it?

The code I am looking to get to operate inside the CSS is much like

$maincolor = $cap->br_main_color;


  • Disregard the caching problem. Case an individual project.
  • Passing the variable within the connect to the stylesheet is simply too complex with this (for me).

EDIT: As a little more explanation: What I am doing is producing a whole theme based of numerous colors and calculating shades for hover effects etc. Roughly 50% from the styles possess some PHP within them. Everything works all right basically by hand input colors to create.perl but I am attempting to make it even simpler at a lower price tech-savvy people and employ one picker.

Here's a different to embedding php inside a Wordpress .css stylesheet (the effectiveness i am unsure on) that does not require manipulation from the Wordpress core.

Just make the php embedded css file inside your theme dir that contains the typical code:


/* define document as css*/
<?php header("Content-type: text/css"); ?>

/* Example php variable declaration and function call */
<?php $body_color = get_color(); ?>

/* Begin php embedded css code below here */
body {
    background: none;
    color: <?php echo $body_color ?>;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 10pt

Then import this dynamic file to your styles style.css to ensure that it's not necessary to customize the Wordpress core.


Theme Name: Mytheme
Version: 1.0
Description: This theme has php embedded css
Author: You
@import url(embedded_style.php);
/* Normal CSS below as required */

my 2 cents

The genesis of the snippet was an effort to permit different directory names when posting css from the parent-theme to my child. I did not like the thought of modifying core wordpress files however since many functions/hooks aren't defined in the style.css runtime to destroy the phone call it had been essential to locate an alternate method. Ultimately I've not used this for the similar reasons I could not interrupt the file-call (too soon to make use of wordpress convenient constants etc.), however hopefully it will be helpful for another person.

To gain access to the wordpress functions you have to range from the following lines on the top of the style.php file.

define('WP_USE_THEMES', false);

The very first line informs wordpress to not run theme related processes and also the second line runs the wordpress engine. Following this point you can get the wordpress functions and also the global variables.