0

I've added theme support for a custom background/color along with a callback and it seems to be breaking my media uploader, as while the uploader box appears, uploads result in an error and image selection doesn't load any images.

My code is:

function my_custom_background_callback() {
    /* Get the background image. */
    $image = get_background_image();

    /* If there's an image, just call the normal WordPress callback. We won't do anything here. */
    if ( !empty( $image ) ) {
        _custom_background_cb();
        return;
    }

    /* Get the background color. */
    $color = get_background_color();

    /* If no background color, return. */
    if ( empty( $color ) )
        return;

    /* Use 'background' instead of 'background-color'. */
    $style = "background: #{$color};";

    ?>
    <style type="text/css">body.body { <?php echo trim( $style ); ?> }</style>
    <?php
}
add_action( 'after_setup_theme', 'my_custom_background_callback' );

Can anyone help me understand why it's breaking?

  • 1
    what is breaking and in what way? – Mark Kaplun Mar 21 '16 at 14:19
  • Where is the code that adds theme support? It's relevant to the question. – montrealist Mar 21 '16 at 18:32
0

Long shot, but if you happen to not follow the recommended format and include the number sign with the HEX code when you define the default colour in your theme support, like this:

if (function_exists('add_theme_support')) {
    $defaults = array('default-color' => '#666');
    add_theme_support( 'custom-background', $defaults );
}

Then, with your code above, you will end up with HTML like this:

<style type="text/css">body.body { background: ##666; }</style>

That's going to mess up a lot of things (in the front AND back), not just media uploader.

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.