0

I am trying to add theme support for custom background using the following code in functions.php file:

function supp_custom_bg() {
    $defaults = array(
        'default-color'          => '',
        'default-image'          => '',
        'wp-head-callback'       => '_custom_background_cb',
        'admin-head-callback'    => '',
        'admin-preview-callback' => ''
    );
    add_theme_support( 'custom-background', $defaults );
}
add_action( 'after_setup_theme', 'supp_custom_bg', 20 );

and the options now are activated in the customizer but no effect on the theme.

Note: The wp_head is added to the <head> tag

1

The simplest way to use this feature:

  1. Add add_theme_support( 'custom-background' ); to functions.php
  2. Use body_class() in your body tag like this: <body <?php body_class(); ?>>
  3. use <?php wp_head(); ?> in your head tag

if you go to the customizer should look like this:

enter image description here

  • Thank you very much i was missing the <?php body_class(); ?> – Makiomar Mar 18 '17 at 17:27
0

If you intend to customize how background image is implemented in your theme then do share the code of your _custom_background_cb callback function. If not and simply wanted to add background image then remove wp-head-callback.

  • Actually I tried only the default-color argument but also no response – Makiomar Mar 18 '17 at 13:10
  • Is your _custom_background_cb code print the color or background image in CSS in your head? – Irene Mitchell Mar 18 '17 at 13:23
  • Nothing is printed.. actually I didn't define this function but after the first try using the default-color I copied these lines from codex to check but nothing also changed – Makiomar Mar 18 '17 at 13:52
  • Could you please answer with right way to use this feature with full code and I will try to figuer out what was wrong with me – Makiomar Mar 18 '17 at 13:54
  • I see. if that is the case then you only need add_theme_support( 'custom-background' ); and it should work -: – Irene Mitchell Mar 18 '17 at 13:56

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.