Need help building a filter to edit the output of “image_send_to_editor”

What I’m trying to do is edit the output of image_send_to_editor so that i can make the anchor that wraps around the image have a specific class & rel.

I plan to basically make each image that gets inserted into a post become fancybox capable without having to be in a gallery or using a plugin.

Heres what I have thus far but I need help filling in the blanks…

<?php
add_filter( 'image_send_to_editor', 'fancy_capable', 10, 7);
function fancy_capable($html, $id, $alt, $title, $align, $url, $size ) {
// not sure what to do here???
return "$html";
}
?>

3 Answers
3

Your best bet here would be to use jQuery to grab any link that links to an image and tell it to use fanceybox.

jQuery(document).ready(function($){
    $('a[href$="jpg"], a[href$="png"], a[href$="jpeg"]').fancybox();
});

If you want this to work just for your post content areas use this:

$('.post-content a[href$="jpg"], .post-content  a[href$="png"], .post-content a[href$="jpeg"]').fancybox();

You will need to replace .post-content with whatever HTML parent element wraps the content area.

Leave a Comment