Skip to content

Instantly share code, notes, and snippets.

@imjjss
Created May 17, 2012 06:49
Show Gist options
  • Save imjjss/2717067 to your computer and use it in GitHub Desktop.
Save imjjss/2717067 to your computer and use it in GitHub Desktop.
change banner img using media gallery
<a href="media-upload.php?type=image&TB_iframe=true" class="thickbox" title="Select A Banner Image From Gallery" onclick="return false;" class="thickbox">
<img id="banner_image" src="<?php echo(htmlentities($banner_image)); ?>" width="450" height="25" />
</a>
<input type="hidden" id="banner_image_input" name="banner_image" value="<?php echo(htmlentities($banner_image)); ?>" />
<?php
/*
strip out everything but the image source and updates the form. First, the function eliminates all of the text returned except the image source. It then updates the banner image and the hidden input value that I am using in my form:
*/
function send_to_editor(html) {
var source = html.match(/src=\".*\" alt/);
source = source[0].replace(/^src=\"/, "").replace(/" alt$/, "");
$("#banner_image").attr('src', source);
$('#banner_image_input").attr('value', source);
tb_remove();
}
?>
@imjjss
Copy link
Author

imjjss commented May 17, 2012

this is not as smart as re-attach plugin

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