I’m building a custom WordPress theme and I’m trying to add the ability to use a custom background through the admin panel. I used the example given here in the WP codex.
I’m using WordPress 3.5.2
I am getting the background option and it all appears to work fine until I actual view the page. I have noticed that it adds an internal style which refers to a body with class name “custom-background” but the body’s actual class is “customize-support”.
When I adjust these using Chrome’s debug it applies the correct styling so is it a bug in a WordPress function somewhere?
I’ve tried to find where it would give the body that class but can’t find anything.
functions.php from theme
<?php
/*
* Adds the custom header option to the theme
*/
function addthemeoptions(){
//Default values of the header image
$header_defaults = array(
'default-image' => '%s/images/header.png',
'random-default' => false,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => false,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
//Adds the support to use custom header images
add_theme_support( 'custom-header', $header_defaults );
$background_defaults = array(
'default-color' => '#000000',
'default-image' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $background_defaults );
}
//Execute our custom theme functionality
add_action( 'after_setup_theme', 'addthemeoptions' );
?>
generated style in head
<style type="text/css" id="custom-background-css">
body.custom-background { background-color: #0a0a0a; }
</style>
body tag from debug
<body class=" customize-support" style>
Thanks in advance
Edit:
I’ve found a temporary fix to just add the correct class value into my header.php where body tag is opened but I feel there should be a more complete solution as I’m hard-correcting something that should be generated correctly by a function in WordPress?
Your body tag inside header.php should look:
<body <?php body_class(''); ?>>
i had the same problem and i found in the codex custom background in the last line : ** To override this default behavior, you would have to provide a replacement for the _custom_background_cb() function. **
so i tried to over ride it by coding my own function my_custom_background_cb like this:
i’m now working on how to remove the backround color control from the default colors section.
Edit: okay, in customizer.php just remove the default color section and add yours like this:
then add your custom colors settings and controls.
it works with me, hope to you too.
Happy Coding
Edit 2:
sorry for the second edit 😀 , but i found that we need to replace the default wp-head-callback function with our custom function custom_custom_background_cb ‘as i found a bug’, i also deleted all codes related to color as we created our color options like this:
Happy Coding Again
I had this problem, had just a
<script type="text/javascript>
opened, missing</script