1

I'm trying to add a custom background on a child theme. In the child theme's functions.php, I add add_theme_support( 'custom-background'); and the background option appears under the "Appearance" menu as expected. I add the image that I want, save, and nothing happens. The image won't appear as the background. What am I doing wrong?

Using version 4.3.1.

This is all that's in my child theme's function.php"

<?php

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

add_theme_support( 'custom-background');
  • Are you sure its not just visually hidden? Search the source for the image name. – RiddleMeThis Jan 8 at 14:43
0

custom background can be used in below way:

  $defaults = array(
  'default-color'          => '',
  'default-image'          => '',
  'default-repeat'         => '',
  'default-position-x'     => '',
  'default-attachment'     => '',
  'wp-head-callback'       => '_custom_background_cb',
  'admin-head-callback'    => '',
  'admin-preview-callback' => ''
  );
 add_theme_support( 'custom-background', $defaults );

Example usage:

 $args = array(
  'default-color' => '000000',
  'default-image' => '%1$s/images/testback.jpg',
 );

add_theme_support( 'custom-background', $args );

Example output when you will view source:

 <style type="text/css" id="custom-background-css"> body.custom-background { background-color: #bdd96e; }

For details follow link:

Output:

enter image description here

Thanks!

  • I have tried this method too. It still doesn't work. Specifically, I wrote: $args = array( 'default-color' => '000000', 'default-image' => '../../uploads/2015/10/bg_image.jpg', ); add_theme_support('custom-background', $args); – jack_of_all_trades Oct 16 '15 at 18:13
  • If you want to add from admin section like from appearance tab then you need to look at code file : /wordpress/wp-admin/custom-background.php – jas Oct 16 '15 at 18:14
  • Please view source of your page source, above function will return path like below: yoursite/wp-content/themes/yourtheme/images/bg_image.jpg And just use the same one I given in answer by replacing your image name. – jas Oct 16 '15 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.