Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am including a .css which i parse with php like so

<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_childTheme_url(); ?>/css/productgallery.php" />

Now in productgallery i can not use a global variable (an array) which i have set in functions.php

How do i fix this?

share|improve this question
ok i almost got this one solved by adding `define('WP_USE_THEMES', false); require('../../../../../site/wp-blog-header.php');' to the top of productgallery.php i can echo the array i need to use, but the productgallery is a mess so the wordpress engine is triggering more then i need. –  alex Mar 4 '12 at 14:32
add comment

2 Answers

Short answer, no.

Long Answer

In your comment, you explain that you're including wp-blog-header.php in the PHP file that generates your CSS file. This is a very bad idea.

When your page references your stylesheet, your browser sees the reference and makes a separate HTTP request to your server to pull it down. If the stylesheet is a static file, this isn't a problem. It's usually cached (so the browser loads it locally) or can be served from a CDN (meaning repeated requests never hit your server).

But loading it as a dynamic PHP file means it's not cache-able. Including wp-blog-header.php also means you're loading all of WordPress just to generate that file.

Every request to your site loads WordPress not once, but twice just to generate that one file.

What you should do instead

Extract the dynamic parts of your stylesheet. Then, in your header.php file, include an in-line <style type="text/css"> ... </style> block.

It won't be the cleanest thing in the world, but inside header.php you can use whatever PHP variables you need to generate the CSS. And you external stylesheet stays small, static, and cache-able.

share|improve this answer
Tx for the long answer explanation. Your def. right about that one. No need to load all WP. I am going to try your suggestion. –  alex Mar 4 '12 at 16:23
Great explanation, just what I needed to know! Thanks. –  And Finally Apr 8 '12 at 16:14
add comment

You should be adding stylesheets using the wp_enqueue_style() function inherent to wordpress, this can be called any time after init and before wp_print_styles from anywhere in wordpress (functions.php, plugin file, even a template in some cases).

share|improve this answer
@mOr7if3r, i am aware of that. But in my case i need to generate some dynamic div reference for slider use. –  alex Mar 4 '12 at 16:23
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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