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 using the following code to allow a user to upload a custom image (in addition to header image) through the customizer. Is there a way to crop the image when displaying it?

$wp_customize->add_setting( 'intro-img',
array (
'default' => 'http://example.com/image.png',
)
);

$wp_customize->add_control(
new WP_Customize_Image_Control(
    $wp_customize,
    'intro-img',
    array(
        'label' => 'Intro Image',
        'section' => 'section_one',
        'settings' => 'intro-img'

    )
    )
);

and displaying with:

<?php echo get_theme_mod( 'intro-img', 'http://example.com/image.png' ); ?>
share|improve this question

1 Answer 1

With your method it would be very tricky, if it's possible at all. What you could do is use a custom header with flexible dimensions. That would allow the user to upload the header image and then crop it how ever they needed easily.

// Register Theme Features
function custom_theme_features()  {

// Add theme support for Custom Header
$header_args = array(
    'default-image'          => 'http://example.com/image.png',
    'width'                  => 0,
    'height'                 => 0,
    'flex-width'             => true,
    'flex-height'            => true,
    'random-default'         => false,
    'header-text'            => false,
    'default-text-color'     => '',
    'uploads'                => true,

);
add_theme_support( 'custom-header', $header_args );
}

// Hook into the 'after_setup_theme' action
add_action( 'after_setup_theme', 'custom_theme_features' );
share|improve this answer

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.