views:

72

answers:

1

I'm doing a style.php CSS file so I can use some dynamic variables in the CSS within a Wordpress installation:

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

and so on.

How can I access a global variable from within the style.php file or pass a variable to it?

The code I'm trying to get to work within the CSS is like

$maincolor = $cap->br_main_color;

Also:

  • Ignore the caching issue. This is just a personal project.
  • Passing the variable in the link to the stylesheet is too complex for this (in my opinion).

EDIT: As a bit more explanation: What I'm doing is generating an entire theme based of a number of colors and calculating shades for hover effects etc. Roughly 50% of the styles have some PHP within them. Everything works just fine if I manually input colors to style.php but I'm trying to make it even simpler for less tech-savvy people and use a color picker.

+2  A: 

To access the wordpress functions you need to include the following lines on top of your style.php file.

define('WP_USE_THEMES', false);
require('./wp-blog-header.php');

The first line tells wordpress not to run theme related processes and the second line runs the wordpress engine. After this point you have access to the wordpress functions and the global variables.

Nithesh Chandra
Fantastic, that does the trick.
Anders H