Styling The Background Of Your Theme

Changing the background color of your website is one of the most common customizations WordPress users ask for on the forums.

The answer can be theme specific, so i thought i’d list the solutions which cover all themes.

Lets start with Genesis because this theme framework has many hidden benefits that make it the best in my opinion.

Styling Genesis Background

Genesis offers a built in function which adds support for custom backgrounds.

All you need to do is add 1 line of code to your child themes functions.php

/** Add support for custom background */
add_theme_support( 'custom-background' );

This code enables a custom background page to be added below the Appearance menu in your Dashboard.

Here you can add a background image and also change the background color quickly and easily.

Custom Background

Adding Background Image To Theme

Again, StudioPress child themes offer the easiest way to add a custom background image.

You can simply add this PHP code to your child themes functions.php file and add your background image to your child themes images folder.

add_theme_support( 'custom-background', array(
	'default-image' => get_stylesheet_directory_uri() . '/images/background.png',
	'default-color' => 'e5e5e5',
) );

If you’re using another theme which doesn’t provide support for custom backgrounds, then you’ll need to add CSS code to your child themes style.css file.

/* Add Background Image
------------------------------------------------------------ */
body {
background-image: url('images/bg.png');
}

In this example, the background image is named bg and has been uploaded to the child themes images folder.

If your theme doesn’t use an images folder, you can create one or upload the image to your media library and enter the full url to the image between the brackets in the code. Example:

/* Full url to Image
------------------------------------------------------------ */
body {
background-image: url ('http://wpsites.net/wp-content/uploads/2013/01/bg.png');
}

Changing Background Color

Changing the color of your background is easy.

Simply add this code to your child themes style.css file and change the value of the hex color code.

body {
background-color: #80000;
}

Background Image & Color

You may have noticed that a background image can take a few seconds to load.

This is especially true on large file sizes, poor hosting and lack of caching and/or CDN setup for your images.

The solution is to also add a background color which matches your background image color.

body { background: #000 url ('black-cloud.png') ; }

This declaration includes 2 properties in one.

You could also use 2 properties in the one declaration:

body {
background-color: #80000;
background-image: url ('images/bg.png');
}

Change Content Area Background Color

You may also like to change the background color of your content area.

#content {
	background: red;
}

Or this code for sites running HTML 5

.entry-content {
	background: red;
}

Add Different Background Image On Specific Page

The easiest way to display a unique background image on one or more pages/posts is to install a plugin like Custom Background Extended.

Changing One Specific Page/Post Background

You’ll find this tutorial useful if you want to customize the background color of one specific page or post.


Comments

9 responses to “Styling The Background Of Your Theme”

  1. Hi Brad
    Great tutorial.
    I have set a background image for my site. I want most (if not all) pages to show this background image. What is the best way to make all the elements/content have a transparent background so that you can see the background image for site behind the text?

    1. Brad Dalton Avatar
      Brad Dalton

      Link to your site please.

      Untested however you can try something like this:

      [code]
      .content .entry {
      background-color: transparent;
      }
      [/code]

  2. Hi Brad, i have been following you tutorials and its so helpful. I just have a couple questions, how to formatting your background to be so beautiful. Its look like graphic/image infographic but its text with custom background in specific theme (with couple image).

    Regards

    1. Brad Dalton Avatar
      Brad Dalton

      This is all it is:
      [code]
      body {
      background: #FBF7D1;
      }
      [/code]

  3. I use Metro Pro on one of my websites, it has built in js support called Backstretch to stretch the background.

    The only thing I was missing from the setup of the theme was the optimal image size to stretch for it to work and not look bad.

    The author of the plugin has a demo, so I just checked the source image size for his demo, the width of his image is 1200px x 800px.

    So when I was done with my image, I ended up with a 52 kb png 1200ps x 675px.

    *Tip* In the process of further decrease the file size, I stumbled upon an online image optimizer called http://media4x.com/image/ it works great.

    To make things clear lets called the original image A, after the first pass of optimization I ended up with image B, I then uploaded image B again to squeeze it a bit more, the resulting image C ended up being at 7.31 kb from 52 kb

    Hope that helps.

    -Ken

    1. Brad Dalton Avatar
      Brad Dalton

      Thanks for sharing your tips Ken.

  4. kristie Avatar
    kristie

    Hi. Great tutorial, do you know what the best size for a background image is?

    1. Brad Dalton Avatar
      Brad Dalton

      Good question Kristie. I think it really depends on whats in the image but to be honest, i don’t really know and would like to find out how to work out the answer to your question.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.