Applying automatic link class to images embedded to posts

I’d really love to be able to conditionally apply a CSS class to link elements of images embedded into posts, but I can’t seem to figure this one out.

Basically what I’d like to achieve is to replace the default embedded image link that links the image to the full size version of itself to opening it in a colorbox.

I know I can achieve this with a bit of Javascript-trickery, but I’d love to figure out how to do this in the server side and then just attach the colorbox functionality in a straightforward manner.

So, is there a filter I should add or what’s the route to take here. Ideally I’d love to be able to write the code so that if a user embeds an image, the link opens the full size version in a colorbox but if the user specifies a custom link, it’ll work like a regular link. This shouldn’t be that hard.

Thanks a lot for any help in advance!

4 Answers
4

You can run a filter on image_send_to_editor, the filter runs inside the get_image_send_to_editor function which is resposible for sending the link HTML that surrounds images sent to the editor.

The filter can be found in core, in wp-admin/includes/media and is linked below for quick reference.
core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/media.php

Leave a Comment