#[1]gnikyt feed [2]gnikyt Code ramblings. Get original sized images from a Wordpress Post Gallery /* Nov 08, 2014 — 1.5KB */ Recently, I was working on a project where I needed to modify an existing page that had multiple galleries. This change required me to have access to the original uploaded images. Here’s a simple function I wrote which returns the images easily in an array format. # Input Hey comes see my gallery! [gallery ids="12,124,342] # Code $images = getGalleryImages(get_the_content()); # Output Array ( [0] => http://xxxx/wp-content/uploads/2014/09/Olin_24_large.jpg [1] => http://xxxx/wp-content/uploads/2014/11/Jw_large.jpg [2] => http://xxxx/wp-content/uploads/2014/11/cresand-D_large.jpg ); /* * getGalleryImages * * Converts a WP gallery into an array of images to use. * * @param $content rendered content (ex: get_the_content()) * @param $return_size size of image to return * @return array */ function getGalleryImages($content, $return_size = 'large') { // Gallery is in format of [gallery link="..." ids="12,124,342"] preg_match('/ids="([^"]*)"/i', $content, $matches); $images = []; if (isset($matches[1])) { foreach(explode(',', $matches[1]) as $id) { // For each image in the gallery, get its WP data (url, width, height) $images[] = wp_get_attachment_image_src($id, $return_size); } } return $images; } [3]MD | [4]TXT | [5]CC-4.0 This post is 10 years old and may contain outdated information. __________________________________________________________________ [6]Ty King Ty King A self-taught, seasoned, and versatile developer from Newfoundland. Crafting innovative solutions with care and expertise. See more [7]about me. [8]Github [9]LinkedIn [10]CV [11]RSS * * * * * * * * * * References Visible links: 1. /rss.xml 2. / 3. /get-original-sized-images-from-a-wordpress-post-gallery/index.md 4. /get-original-sized-images-from-a-wordpress-post-gallery/index.txt 5. https://creativecommons.org/licenses/by/4.0/ 6. /about 7. /about 8. https://github.com/gnikyt 9. https://linkedin.com/in/gnikyt 10. /assets/files/cv.pdf 11. /rss.xml Hidden links: 13. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-1 14. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-2 15. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-3 16. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-4 17. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-5 18. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-6 19. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-7 20. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-8 21. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-9 22. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-10 23. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-11 24. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb1-12 25. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-1 26. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-2 27. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-3 28. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-4 29. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-5 30. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-6 31. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-7 32. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-8 33. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-9 34. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-10 35. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-11 36. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-12 37. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-13 38. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-14 39. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-15 40. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-16 41. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-17 42. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-18 43. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-19 44. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-20 45. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-21 46. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-22 47. localhost/tmp/lynxXXXXvUgP4U/L770542-9809TMP.html#cb2-23