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 add an image in my CSS with the theme folder code, <?php bloginfo('template_directory'); ?>, which works in HTML but for some reason it's not working in the CSS. Does anyone know why or a solution?

Here's my code:

background: url("<?php bloginfo('template_directory'); ?>/images/bg.jpg");
share|improve this question
up vote 4 down vote accepted

That's because php code inside a CSS file is not parsed unless you configure your server to. Just use it as a relative path to the image (as per the CSS file).

background: url("images/bg.jpg");

share|improve this answer
That's what I'm doing now. Thanks for the explanation! – talkingD0G Apr 11 '11 at 20:31

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.