Решено. Нашел другой код, который прописал вместо прежнего:
add_filter('the_content', 'addrellightbox');
function addrellightbox($content) {
global $post;
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)title=('|\")(.*?)('|\")(.*?)<\/a>/i";
$replacement = '<a$1href=$2$3.$4$5 title=$8$9$10 rel="lightbox[%LIGHTID%]"$6class="lightbox">$7title=$8$9$10$11</a>';
$content = preg_replace($pattern, $replacement, $content);
$content = str_replace("%LIGHTID%", $post->ID, $content);
return $content;
}