I'm having an issue with WP_Customize_Cropped_Image_Control in the Customizer. The default image that I have set doesn't show up in the side pane of Customizer where you upload and when I upload a new image, it just outputs a number, presumingly the image ID. The moment I change WP_Customize_Cropped_Image_Control to WP_Customize_Image_Control, everything works. The default image and uploaded images both display in the customizer and preview window.

Is there a different way of setting/displaying the default image for a default cropped image in the customizer?

This is the code I have in my customizer.php:

$wp_customize->add_setting( 'bio_image', array(
    'default'           => get_template_directory_uri() . '/images/default.jpg',
    'transport'         => 'postMessage'
) );    
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'bio_image', array(
    'label'             => __( 'Image', 'myTheme' ),
    'flex_width'        => false, 
    'flex_height'       => false,
    'width'             => 330,
    'height'            => 330,
    'settings'          => 'bio_image'
) ) );

This is the code I have in my customizer.js:

wp.customize( 'bio_image', function( value ) {
    value.bind( function( newval ) {
        $('#bio-image').attr( 'src', newval );
    } );
} );

This is the code I have in my template file:

<img id="bio-image" src="<?php echo get_theme_mod( 'bio_image' , get_template_directory_uri().'/images/default.jpg' ); ?>">

Your Answer

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

Browse other questions tagged or ask your own question.