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.

1 Answer 1


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;
  • And is there no other way in applying the same thing to the_content() rather than to image_send_to_editor? Commented May 31, 2012 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
    Commented May 31, 2012 at 7:45
  • ok, thank you! I did manage to do it with the image_send_hook Commented May 31, 2012 at 8:30
  • I hope you don't have to redo a lot of existing images.... PS have you considered a lightbox?
    – janw
    Commented May 31, 2012 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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