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

The custom header feature allows (in some code I have found) to suggest several default images to use in the custom header.

Could the same be built in the custom background?

The idea is to have already some textures available for the user to choose from in the theme.

Any ideas?

share|improve this question

if you are asking default background image for add_theme_support( 'custom-background'); then it can be set using 'default-image' => get_template_directory_uri() . '/images/pattern.png',

complete code will look like below.

$args = array(
'default-color'  => 'f0f0f0',
'default-repeat' => 'fixed',
'default-image'  => get_template_directory_uri() . '/assets/images/pattern.png',
add_theme_support( 'custom-background', $args );
share|improve this answer

I would suggest outputting a line of CSS in your header.php file, something like

<?='.body {background-image:url(/your/path/to/images/'.$YOUR_CHOSEN_IMAGE.'.png);}'?>
share|improve this answer
That's not really what I was looking for. – Offcourse Jul 13 '12 at 11:17
I could use something that presents 4 or 5 default background images to choose from in the admin area, in the background section of the theme options. – Offcourse Jul 13 '12 at 15:49

I'm not really sure what you're asking, but here goes.

Assuming that you already know the options settings api, here's a form you can use to implement that idea:

    <label for="bg1">
      <img src="http://lorempixel.com/50/50" />
      <input class="select_control" id="bg1" name="bg" type="radio" value="bg1" />

    <label for="bg2">
        <img src="http://lorempixel.com/50/50" />
        <input class="select_control" id="test2" name="bg" type="radio" value="bg2" />

    <label for="bg3">
        <img src="http://lorempixel.com/50/50" />
        <input class="select_control" id="bg3" name="bg" type="radio" value="bg3" />


Convert that using the settings API, then use get_option() to retrieve your background image url to display it.

If you want to change the CSS, background: url(), based on the option value. Then you might need to know how to use CSS in PHP.

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

 <?php if (get_option('your_background_image') != '') : ?>
 body {
      background: url( <?php echo get_option('your_background_image'); ?>;
 <?php endif; ?>
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.