$post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', //'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' )); // If there is more than 1 attachment in a gallery... if (count($attachment_ids) > 1) { foreach ($attachment_ids as $attachment_id) { if ($attachment_id == $post->ID) { $next_id = current($attachment_ids); break; } } unset($attachment_id); if (isset($next_id)) { // get the URL of the next image attachment... $next_attachment_url = get_attachment_link($next_id); } else { // or get the URL of the first image attachment. $next_attachment_url = get_attachment_link(array_shift($attachment_ids)); } unset($next_id); } $output = ''; $type = get_post_mime_type($post->ID); switch (strtolower($type)) { case 'audio/mp3': case 'audio/mpeg': case 'audio/mpeg3': case 'audio/mpg': case 'audio/wav': case 'audio/wave': case 'audio/webm': case 'audio/x-wav': $output = do_shortcode('[audio '.$metadata['fileformat'].'="'.wp_get_attachment_url($post->ID).'"][/audio]'); break; case 'image/bmp': case 'image/gif': case 'image/jpeg': case 'image/pjpeg': case 'image/png': case 'image/x-png': $output = sprintf( '%3$s', esc_url($next_attachment_url), the_title_attribute(array('echo' => false)), wp_get_attachment_image($post->ID, $attachment_size, false, array('class' => 'img-fluid aligncenter')) ); break; case 'video/mp4': case 'video/mpeg': case 'video/quicktime': case 'video/webm': case 'video/x-ms-wmv': case 'video/x-msvideo': $output = do_shortcode('[video width="'.$metadata['width'].'" height="'.$metadata['height'].'" '.$metadata['fileformat'].'="'.wp_get_attachment_url($post->ID).'"][/video]'); break; default: $output = '