I use this custom sanitizer to get the appropriate image size so that anyone using my themes can't mess up and put an 8k image in the website. The code works, but the problem I have is that once the code sanitizes the image and returns to the customizer the image doesn't update... the old image just stays displayed and is got a shade of grey over it. What am I missing? If I switch the sanitize function below to say "esc_url" the images work just fine.

function semperfi_sanitize_image( $input , $setting ) {

    $postid = attachment_url_to_postid( $input );

    $input = wp_get_attachment_image_src( $postid , $setting->manager->get_control( $setting->id )->input_attrs[img_size] )[0];

    if ( $postid != 0 )

        return esc_url( $input );


        return esc_url( $setting->default );


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.