开发者

How to append _thumb to all media uploaded and media that is already uploaded to my wordpress blog

I was hoping to get some help on this one. I am looking to have appended to all images and media 开发者_如何学Cthat get applied to a post via the upload tool in WordPress _thumb to the src of the media object.

Thanks,

Matt


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜