WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I'm trying to specify a background image in a style in a plugin I'm making. I was just outputing tags from the php, but realized I should probably be using enqueue_style... But how do I put a line of code like this:

.star.half {
    background:url(<?php echo plugins_url(); ?>/my-plugin/images/star-half.png) no-repeat 0px 0px;

Into a plain .css file? What do I put where it says <?php echo plugins_url(); ?>?

share|improve this question
up vote 3 down vote accepted

Just add a STYLE tag in 'wp_head'.

// Anonymous function, PHP 5.3+, extract function for 5.2
add_action('wp_head', function(){
    echo '<style type="text/css">';
    // Add background style here
    echo '</style>';

Add this in your functions.php. Don't stuff too much CSS in it, just the dynamic bg image you need.

It's not the easiest thing to create a dynamic CSS file so, just for a bg image, use this method.

share|improve this answer

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.