Hi I have taken over a website with half-customized theme. It was an outdated theme with bunch of scripts and formatting. Currently I encountered a small issue when enqueue stylesheets in functions.php instead of header.php (since all of them were included directly in the header.php).

Problem #1

Theme has specific 'style.php' loaded directly to header.php files which has:

header("Content-type: text/css",true); 

function compress($buffer) {
  /* remove comments */
  $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  /* remove tabs, spaces, newlines, etc. */
  $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
  return $buffer;

/* css files */
include('css/custom.css'); // ALL CUSTOMIZATION goes here!


and I am wondering whether to load all files separately or somehow enqueue .php file.

Problem #2

It has dynamic option to change colors and thus this is loaded straight to header.php with lines:

<?php $primary_color = $data['primary_color'];?>
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/color.php?color=<?php echo substr($primary_color,1) ?>" type="text/css" media="screen" />

How can I move this to functions and use regular wp_enqueue?

Thank a lot!

  • yes, i know how to include them to header. however how to include .php files with custom setting via wp_enqueue is a mystery to me :) Commented Dec 22, 2014 at 11:39
  • As you have header("Content-type: text/css",true);, that file can be used as CSS file. Use wp_enqueue_style as usual. It should work.
    – cybmeta
    Commented Dec 22, 2014 at 12:14

1 Answer 1


From the enqueue point of view it doesn't matter if it points to genuine static CSS file or endpoint that dynamically generates it.

However there is a massive performance implication. Loading PHP engine (and worse — WordPress core on top) is much much more resource intensive than serving static file.

Your end goal shouldn't be converting this, but getting rid of this altogether. If that is a standalone site (and not theme meant for redistribution) it should be pretty easy to generate desired modification once and serve them as static files from that point.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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