loadHTML($content); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { if($image->getAttribute('data-id')) { $id = $image->getAttribute('data-id'); } else { $class_pieces = explode("-", $image->getAttribute('class')); $id = end($class_pieces); } // Format for lightbox wants an object $parse_images[$id] = [ 'src' => $image->getAttribute('src'), 'alt' => $image->getAttribute('alt'), 'title' => wp_get_attachment_caption($id), 'description' => get_the_excerpt($id) ]; } return $parse_images; } ?>