All WordPress theme should support Custom Background feature which allows theme users to set their own Background Image and Color. In this tutorial I will explain how to enable and use WordPress Background Image feature.
Just follow the below 2 steps for enabling and making use of this feature in your WordPress theme.
Enable it by adding the following code in your theme functions.php file.
/*Custom background*/ $args = array( 'default-color' => '000000', 'default-image' => get_template_directory_uri().'/Images/background.jpg', ); add_theme_support( 'custom-background', $args ); /*End*/
Note that I have provided the default color and image to our theme from the $args argument. You can simple remove the argument (if you don’t want to provide default values) and just add – add_theme_support( ‘custom-background’);.
Update your theme HTML body tag to provide body_class like this –
<body <?php body_class(); ?>>
It will give the body element different CSS classes including custom-background class through which the custom background image and color are applied.
To change the Background Image go to Appearance > Background in the dashboard. Then
Under the heading Background Image click Select Image.
Next, select the image or upload a new image, then click Save & Publish button to save the background image.
To change the Background Color – in the same place under the heading ‘Colors’, you will see ‘Background Color’. Click Select Color button to select the background color of your choice and finally click Save & Publish button.
Share this article -