Skip to content

Instantly share code, notes, and snippets.

@PhilippSchreiber
Created September 26, 2013 10:56
Show Gist options
  • Save PhilippSchreiber/6712643 to your computer and use it in GitHub Desktop.
Save PhilippSchreiber/6712643 to your computer and use it in GitHub Desktop.
Modify the image URL used in Wordpress Media Frame.
function ps_wp_prepare_attachment_for_js($response, $attachment, $meta) {
if($response['type'] == 'image') {
$image_src = wp_get_attachment_image_src( $response['id'], 'thumbnail' ); //Use any image size added to your wordpress installation
if( is_array($image_src) ) {
$response['url'] = $image_src[0];
}
}
return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'ps_wp_prepare_attachment_for_js', 10, 3 );
@danielucas
Copy link

you rock - was trying to get this same thing working for almost an hour before finding this. epic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment