How to add Custom width & Height to our custom image uploader
function clientPic6( $wp_customize ) {
$wp_customize->add_setting( 'client_background_img_6'); // Add setting for logo uploader
// Add control for logo uploader (actual uploader)
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'm1_client_img_6', array(
'label' => __( 'Client Image', 'm2_C6' ),
'section' => 'custom_client_block',
'settings' => 'client_background_img_6',
) ) );
}
add_action( 'customize_register', 'clientPic6' );
How to add Custom width & Height to our custom image uploader
function clientPic6( $wp_customize ) {
$wp_customize->add_setting( 'client_background_img_6'); // Add setting for logo uploader
// Add control for logo uploader (actual uploader)
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'm1_client_img_6', array(
'label' => __( 'Client Image', 'm2_C6' ),
'section' => 'custom_client_block',
'settings' => 'client_background_img_6',
) ) );
}
add_action( 'customize_register', 'clientPic6' );
Share
Improve this question
edited Apr 25, 2017 at 13:32
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Apr 25, 2017 at 11:17
M.NadeemM.Nadeem
13 bronze badges
1
- You mean you want to allow only images of a certain size to be uploaded? Or you want fields for the height and width, so the client can set them? – cjbj Commented Apr 25, 2017 at 11:56
1 Answer
Reset to default 2You may be looking for WP_Customize_Cropped_Image_Control
which has width
and height
parameters (along with flex_width
and flex_height
). This will then present you with the image dimensions when you select an image in the Customizer. For example, refer to how the Custom Logo control is registered in core:
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'custom_logo', array(
'label' => __( 'Logo' ),
'section' => 'title_tagline',
'priority' => 8,
'height' => $custom_logo_args[0]['height'],
'width' => $custom_logo_args[0]['width'],
'flex_height' => $custom_logo_args[0]['flex-height'],
'flex_width' => $custom_logo_args[0]['flex-width'],
'button_labels' => array(
'select' => __( 'Select logo' ),
'change' => __( 'Change logo' ),
'remove' => __( 'Remove' ),
'default' => __( 'Default' ),
'placeholder' => __( 'No logo selected' ),
'frame_title' => __( 'Select logo' ),
'frame_button' => __( 'Choose logo' ),
),
) ) );