views:

29

answers:

2

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

A: 

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 :)

HurnsMobile
ThanX HurnsMobile... I was hoping for smething on the backend.
Matthew
+2  A: 

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);
TheDeadMedic
Thanks let me implment this and get back to you guys.
Matthew