Hello guys,
I was hoping to get some help on this one. I am looking to have appended to all images and media that get applied to a post via the upload tool in WordPress _thumb to the src of the media object.
Thanks,
Matt
Hello guys,
I was hoping to get some help on this one. I am looking to have appended to all images and media that get applied to a post via the upload tool in WordPress _thumb to the src of the media object.
Thanks,
Matt
Assuming you are trying to do this on the front-end, a simple solution would be something like the following:
Assuming something like:
<img src='image1.png'>
<img src='image2.png'>
jQuery as follows:
var $allImages = $('img');
$allImages.each( function() {
var curUrl = $(this).attr('src');
var newUrl = '_thumbs/' + curUrl;
$(this).attr('src',newUrl);
})
Would result in the following HTML:
<img src='thumbs_/image1.png'>
<img src='thumbs_/image2.png'>
And finally a working example at jsfiddle - http://jsfiddle.net/BTRax/7/
If you were trying to do this on the backend in PHP well then someone else will need to chime in :)
Check out this SO wordpress-3-0-media-uploader-alters-my-image-filename.
You could modify it something like;
function my_upload_prefix( $filename, $filename_raw ) {
if( "_thumb" != substr($filename_raw, 0, 6) )
$filename = "_thumb" . $filename;
return $filename;
}
add_filter('sanitize_file_name', 'my_upload_prefix', 10, 2);