Support » Themes and Templates » bloginfo() not working correctly (or as intended) in style.php

  • Resolved Syewatts


    Hi all. I’m very new to WP and editing my first theme (an edit of the Sandbox Theme.) I come from a design background, so my PHP is not very impressive, which is probably why I have hit a roadblock.

    What I want to do is set the background image of <body> in my CSS. The theme links style.css to the header, and style.css links to another CSS file, which I have as a php file (myedit.php) because I wanted some of the background images to randomise.

    The problem is that it doesn’t work. My first attempt was to have a simple background image in the body tag, like so:

    body {
    background: url(<?php bloginfo('template_directory'); ?>/images/bg-images/bgimage.jpg);

    This makes the all everything defined in ‘myedit.php’ not work, it’s as if the file isn’t even there. Moving ‘body {}’ around, I found that it’s everything below the <?php bloginfo('template_directory'); ?> which is blanked out.

    Anyone have any idea why this is happening? I can use other bits of PHP code in ‘myedit.php’, but calling bloginfo(‘template_directory’) seems to give it a headache. If I cannot use bloginfo to get the directory, does anyone else have an alternative way that I can set background images in the CSS? I have also tried hard-wiring it (wp-content/theme/sandbox/images/bg-images/bgimage.jpg) which did not work either.

    Thanks for reading, your help is much appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • jack randall


    my guess would be that wordpress needs to be told to look for that css construction as it’s not a particularly standard way of doing things.

    take a look at this and see if it makes some sense to you.

    That’s cleared a few things up, I managed to work around it.

    Thanks for your help~

    jack randall


    glad it made sense to you! i’ve been tweaking about with websites and wordpress for about 5 years now and i had no idea you could embed php in css files!

    you learn something new every day 😀

    Well I’ve seen a few things around the web which suggests that bloginfo() Only works after a certain point. I assumed because bloginfo() is used to CALL the stylesheet, it would work but I guess it didn’t.

    I ended up moving my second stylesheet into the same directory as the first and hard-wiring all the backgrounds. I feel cheap 🙁

    jack randall


    whatever gets your code through the night 😀 sometime the simplest option is the best!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘bloginfo() not working correctly (or as intended) in style.php’ is closed to new replies.