Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to add a second background image function to my theme customizer with this code.

    // HTML Background Image
$wp_customize->add_setting(
    'html_background_image', 
    array(
        'capability'     => 'edit_theme_options',
));

$wp_customize->add_control( 
    new WP_Customize_Background_Image_Control(
        $wp_customize,
        'background_image', 
        array(
            'label'    => __('HTML Background Image', 'TEXTDOMAIN'),
            'section'  => 'background_image',
            'settings' => 'html_background_image',
)));

But it doesn't work. Am I missing something here?

share|improve this question
    
Do you have this code hooked to the customize_register action? Is it contained inside a function? –  bungeshea Jan 18 '13 at 3:08
    
Yes, everything else works fine. –  Daniel Jan 18 '13 at 3:13
    
What does var_dump (get_theme_mod( 'background_image')); show –  Wyck Jan 18 '13 at 5:04
    
It shows: string(0) "" –  Daniel Jan 18 '13 at 5:10
add comment

1 Answer

There's very little documentation on this class, but here below is the full example from WordPress core (here's github). Note you'd be using the $wp_customize object you get as argument to your custom_register callback and not $this as does the core class. I've done a search and replace below and it works.

        /* CORE COPY PASTE */
        //https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-manager.php#L808

        /* Custom Background */

        $wp_customize->add_section( 'background_image', array(
            'title'          => __( 'Background Image' ),
            'theme_supports' => 'custom-background',
            'priority'       => 80,
        ) );

        $wp_customize->add_setting( 'background_image', array(
            'default'        => get_theme_support( 'custom-background', 'default-image' ),
            'theme_supports' => 'custom-background',
        ) );

        $wp_customize->add_setting( new WP_Customize_Background_Image_Setting( $wp_customize, 'background_image_thumb', array(
            'theme_supports' => 'custom-background',
        ) ) );

        $wp_customize->add_control( new WP_Customize_Background_Image_Control( $wp_customize ) );

        $wp_customize->add_setting( 'background_repeat', array(
            'default'        => 'repeat',
            'theme_supports' => 'custom-background',
        ) );

        $wp_customize->add_control( 'background_repeat', array(
            'label'      => __( 'Background Repeat' ),
            'section'    => 'background_image',
            'type'       => 'radio',
            'choices'    => array(
                'no-repeat'  => __('No Repeat'),
                'repeat'     => __('Tile'),
                'repeat-x'   => __('Tile Horizontally'),
                'repeat-y'   => __('Tile Vertically'),
            ),
        ) );

        $wp_customize->add_setting( 'background_position_x', array(
            'default'        => 'left',
            'theme_supports' => 'custom-background',
        ) );

        $wp_customize->add_control( 'background_position_x', array(
            'label'      => __( 'Background Position' ),
            'section'    => 'background_image',
            'type'       => 'radio',
            'choices'    => array(
                'left'       => __('Left'),
                'center'     => __('Center'),
                'right'      => __('Right'),
            ),
        ) );

        $wp_customize->add_setting( 'background_attachment', array(
            'default'        => 'fixed',
            'theme_supports' => 'custom-background',
        ) );

        $wp_customize->add_control( 'background_attachment', array(
            'label'      => __( 'Background Attachment' ),
            'section'    => 'background_image',
            'type'       => 'radio',
            'choices'    => array(
                'fixed'      => __('Fixed'),
                'scroll'     => __('Scroll'),
            ),
        ) );

It appears you cannot customize the e.g. section, and for evidence look to this code for the third argument to WP_Customize_Image_Control

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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