WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How can I use WordPress functions in my stylesheet?

I have a file, custom.php, thats basically a stylesheet with php variables for the styles. I used this guide to make it but Im not sure how to use the style sheet in my theme. Here is my /styles/custom.php:

header("Content-type: text/css"); 
div{background-color:<?php echo "red" ?>;}

and my functions.php file has this:

wp_enqueue_style("custom", $root."/styles/custom.php"); 

So the custom.php file should be rendered as a stylesheet right? But my wordpress site doesnt load the file contents. When I look at the source code via firebug and expand the custom.php file all I see is:

Reload the page to get source for: http://samsung/wordpress/wp-content/themes/kjd/styles/custom.php?ver=3.4.1

This is on my dev machine running Ubuntu 12.04, LAMP and Wordpress 3.4.1

share|improve this question

marked as duplicate by toscho Jan 4 '13 at 0:28

This question was marked as an exact duplicate of an existing question.

Is this custom.php file a part of you theme? – Rutwick Gangurde Aug 22 '12 at 5:20
What do you mean? It's in my theme directory and Im calling the file in functions.php with wp_enqueue_style – rugbert Aug 22 '12 at 5:28
If its a part of your theme, means it has the get_header() function call, which automatically enqueues the style.css. If it's not a part of your theme, then why do you need the style.css on it? – Rutwick Gangurde Aug 22 '12 at 10:17
No see, this is custom.php is basically a CSS file that uses php variables for the styles. It's not a page template or anything. Edited for clarification – rugbert Aug 22 '12 at 14:04

Not sure if that's what you need, but take a look.

// Can be put into function.php

if ( !is_admin() ) { 
    add_action( "wp_enqueue_scripts", "enqueue_scripts", 11 ); 
function enqueue_scripts() {

    // Theme CSS (style.css)
    wp_enqueue_style( 'style-file', get_template_directory_uri() . '/style.css',false,'1.0','all' );

    // JS
    wp_register_script( 'script', get_template_directory_uri() . '/your-script.js', array('jquery') );
    wp_enqueue_script( 'script' );


Or use ...

// Used to include PHP
include_once(TEMPLATEPATH . 'script.php');

Sometimes it helps to also tell the .htaccess file how files should be handled. Throw this in your .htaccess file.

# handler for phpsuexec..
<FilesMatch "\.(css|style)$">
 SetHandler application/x-httpd-php
share|improve this answer
I have whats in the first part of what you have, thats what Im using to send my stylesheets to the wp_head() but what I need to do is get my php driven stylesheet to work. I edited my question for clarity – rugbert Aug 22 '12 at 21:11
I have updated the code above. – marcup Aug 22 '12 at 21:26
ahhh ok cool yeah, I just found this site and at the bottom it says to use <FilesMatch "^.*?style.*?$"> SetHandler php5-script </FilesMatch> Which KIND OF works, it conflicts with my other style sheets. It seems that if there is content in my main style sheet then it completely ignores this new custom one. – rugbert Aug 23 '12 at 1:57
hmm ok so I think it's working now. the custom.css file has to have html{} in it. But it doesnt accept php variables – rugbert Aug 23 '12 at 3:02
Did you try the .htaccess snippet? – marcup Aug 23 '12 at 5:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.