$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme customizer - How to add width & height (resolution) on wordpress function?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme customizer - How to add width & height (resolution) on wordpress function?

matteradmin10PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

You 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' ),
    ),
) ) );
Post a comment

comment list (0)

  1. No comments so far