I want to have such feature that when users post in the comment link to the image (jpg, png etc) in would have [img][/img] around it and have rel="fancybox"to open it in the modal window.
A have such code, but it's not working as expected :(
add_filter('the_content', 'addrellightbox');
add_filter('comment_text', 'addrellightbox');
function addrellightbox($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '[img]<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>[/img]';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
2supertrue Yeah it's good but not enough :)
Users of my blog do not want to know about [img] [/img] constructions - they only want to post image. And they are doing it with just inserting a link. And I want to show this image as it should be - clickable and with img tags.
So... Any solution?
<img src="path/to/image" />and wrap it in an anchor tag. Shortcodes don't do anything if you've not created a shortcode handler to parse it and output actual html markup. – Milo Sep 23 '11 at 7:10