Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I wonder if it's possible to add a filter to all images inside the_content() to create the following image pattern for all images …

<img class="digest" src="smallest-file.jpg" data-fullsrc="largest-file.jpg" alt="something"/>

So I'd like to add a class="digest" to the img tag. Additionally the src attribute of the image should always link to the smallest-file wordpress creates and a data-fullsrc that links to the largest file of the image.

Any idea or approach on how to do this? I'd really appreciate your help with this as I'm completely helpless right now.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You will need to take a look at the image_send_to_editor filter.
This will not update existing records but it if you get it working it will apply to each newly inserted image.

very basic filter:

function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '' ){
    $html; //contains the string you need to edit, you might want to consider to rebuild the complete string.

    return $html;
}
add_filter('image_send_to_editor','give_linked_images_class',10,8);
share|improve this answer
    
And is there no other way in applying the same thing to the_content() rather than to image_send_to_editor? –  mathiregister May 31 '12 at 7:06
    
It's not impossible, but it will be MUCH harder to do with regex searches and replaces. Also it will give quite a performance hit –  janw May 31 '12 at 7:45
    
ok, thank you! I did manage to do it with the image_send_hook –  mathiregister May 31 '12 at 8:30
    
I hope you don't have to redo a lot of existing images.... PS have you considered a lightbox? –  janw May 31 '12 at 8:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.