All WordPress theme should support ‘Custom Background’ feature which allows theme users to set their own Background Image and Color. In this tutorial we 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 we 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 –
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 WordPress CMS. Under heading ‘Background Image’ click ‘Select Image’. Here 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’, here click ‘Select Color’ button to select the background color of your choice and finally click ‘Save & Publish’ button.