Skip to main content
Cookbook Content NextGEN Gallery

Add Photos to a NextGEN Gallery with AI

New photos added to a NextGEN gallery, with alt text, after a check for photos already in it and a look at what changes.

Difficulty Beginner
Time ~5 min

Prerequisites

A site connected to WPVibe running NextGEN Gallery 4.6.0 or newer (free) on WordPress 6.9 or newer, with an administrator account. Allow AI to edit galleries is turned on in your WordPress admin under Imagely, Settings, AI & MCP. The new photos are already in your media library.

The prompt
My WordPress site uses NextGEN Gallery. Add my photos of [what they show, or words from their titles] to my [gallery name] gallery.

1. Run discover_abilities with category nextgen-gallery. If the NextGEN Gallery abilities are not there, stop and tell me to install the free NextGEN Gallery plugin or update it to 4.6.0 or newer (it needs WordPress 6.9 or newer). Then run nextgen-gallery/describe-gallery-schema. If writes_enabled is false, stop and tell me to turn on Allow AI to edit galleries in my WordPress admin under Imagely, Settings, AI & MCP, then ask again. Never change that setting yourself. Where a step says _fields inside query, put _fields in the query parameters, not in WPVibe's fields option, which on NextGEN's routes keeps whole nested blocks such as meta_data.
2. Run nextgen-gallery/list-galleries with search set to one distinctive word from the gallery name (it matches the text as one phrase), per_page 50 and max_length 100000 (if a response says it was cut, lower per_page and page through). If several match, show them with their image counts and ask which one. If none match, try another word, then run it without search and show me the newest 50; if total_pages is more than 1, ask whether to read the next page.
3. If its image_count is 300 or fewer, read its images with rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, per_page 100, page 1, max_length 100000 and _fields inside query set to pid,filename,image_slug,alttext,exclude,meta_data.md5 (if a full page comes back, read the next page, and so on). If a response says it was cut (truncated), restart at page 1 with a lower per_page. If it is over 300, don't read them all: read the last 10 with rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, orderby pid, order DESC, per_page 10 and _fields inside query set to pid,filename,alttext. Show me how many it has and the last 10 added by alt text and file name. Also tell me visitors see new photos at the end only while NextGEN's gallery sort setting is the custom order (the default).
4. Find where the gallery is shown: run rest_api GET /wp/v2/pages and GET /wp/v2/posts, each four times, with search imagely, ngg, slideshow and imagebrowser, status publish,draft,private,pending,future, per_page 100 and _fields id (if a full page of 100 comes back, read the next page, and so on; an answer of rest_post_invalid_page_number means there are no more). Put the ids together without repeats, keeping pages and posts apart. If there are more than 40, tell me how many and ask before reading them; if I say no, tell me that what you report about where galleries are shown is incomplete. Read their content 10 at a time with rest_api GET /wp/v2/pages (or /wp/v2/posts) with include set to those ids, per_page 10, status publish,draft,private,pending,future, context edit, _fields id,title,status,link,content.raw and max_length 100000. If a response says it was cut (truncated), read those ids fewer at a time; if a post is still cut on its own, read it with rest_api GET /wp/v2/pages/ID (or posts) with context edit, _fields id,status,content.raw and max_length 4000000. Searches also match ordinary words, so a post may show no gallery at all. NextGEN hides a private gallery's client page from every search, so for a gallery whose page_id (from list-galleries or get-gallery) is not 0, also read that page alone with rest_api GET /wp/v2/pages/PAGE_ID with context edit and _fields id,status,link,content.raw, and count it like the others. A post shows the gallery when its content has the imagely shortcode with id set to GALLERY_ID (the Imagely block saves this shortcode inside it), the nggallery, slideshow, nggslideshow, imagebrowser or nggimagebrowser shortcode with id GALLERY_ID, or the ngg or ngg_images shortcode with GALLERY_ID among its gallery_ids or galleries, or with src or source set to galleries and GALLERY_ID among its ids or container_ids (in double, single or no quotes; ids separated by commas or a vertical bar). This does not see galleries inside an album, on other content types such as products or courses, in synced patterns, placed with a page builder widget, a theme template or a sidebar widget, by the random or recent shortcodes, by an ngg shortcode with only an id (a saved display), or by an old Attach to Post placeholder image. Tell me where it is shown. Tell me visitors see the new photos as soon as they are added wherever it is shown, as this search can't see every place: a NextGEN gallery has no draft.
5. Search my media library with rest_api GET /wp/v2/media with search set to my words, media_type image, per_page 50, context edit and _fields id,title,alt_text,caption,source_url. It matches every word in titles, captions and descriptions, so if nothing fits, try each word on its own. Show me the matches as a numbered list with title, alt text (or: no alt text) and source_url as the link, and wait for my pick and its order.
6. For each photo I picked, check whether it may already be in the gallery. Take its file name from source_url, both as it is and without a -scaled or -rotated ending before the extension (NextGEN usually names its copy after the original, but after the -scaled file when the original is gone). If you read all the gallery's images, look for those names there; if not, run rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, search set to the name without -scaled, -rotated or the extension, and _fields inside query set to pid,filename (search also matches longer names, so compare exactly). A gallery image whose filename is either name, or either with a number and an underscore in front (NextGEN names a second copy 1_NAME), means the photo may already be in the gallery: adding it again would show it twice. It may also be a different photo with the same file name, such as IMG_0001.jpg from another month. Show me what will be added, with the marked ones left out unless I name them, and wait for my yes. New photos go at the end of the gallery. Run nextgen-gallery/add-images with the gallery_id and up to 20 attachment_ids at a time, in my order. If any come back in remaining, send those next, not the whole list again. Never send a photo twice: each call imports a fresh copy, so it would show twice. If a call fails or gets no answer, do not send it again: read the gallery's newest images with rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, orderby pid, order DESC, per_page set to how many photos you sent, and _fields inside query set to pid,filename,image_slug,alttext to see what was added, and send only what is missing. Tell me each one in skipped with its reason, and any in warnings. If nothing was added, stop and tell me why.
7. Read the new images with rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, orderby pid, order DESC, per_page set to how many photos you sent, and _fields inside query set to pid,filename,image_slug,alttext, and keep the ones whose pid is among the image_ids add-images returned, or that you found added after a failed call. The added and image_ids lists line up, one image per photo in the same order, so the first image_id came from the first id in added, and so on. An image needs alt text when its alttext is empty, is its file name (the same as its image_slug, or its filename with or without the extension), or is text a camera writes by itself, such as OLYMPUS DIGITAL CAMERA or SONY DSC. NextGEN gives an imported photo the media library caption as its alt text; with no caption, a title saved inside the photo file, if any; otherwise its file name. It never copies the media library alt text. For each new image that needs alt text, propose one: the media library alt_text of the photo it came from (from the media library search) if it has one; otherwise write about 125 characters or fewer, from the photo itself if you can see it at its source_url, else from its title, caption and file name, marked as a guess. Show me the list (image, current alt text, proposed alt text) and wait for my yes or edits. For each approved image, save it with rest_api_write PUT /imagely/v1/images/PID with alttext only. Never change alt text that does not need it by these rules.
8. Run nextgen-gallery/get-gallery and read the newest images again with rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, orderby pid, order DESC, per_page set to how many photos you sent, and _fields inside query set to pid,filename,image_slug,alttext, and confirm each has the alt text you saved. Then read the gallery's last page in its own order (rest_api GET /imagely/v1/images with gallery_id GALLERY_ID, per_page 100, page set to the last page for the new image_count, and _fields inside query set to pid) and confirm the new photos come last; if fewer of them are on that page than you added, read the page before it as well. Tell me the image count before and after, and the photos added. Tell me the abilities can't take photos out: to undo, open the gallery's edit_url from get-gallery in WordPress admin, select the added photos and delete them there.
Already connected?

Skip pasting the full prompt. Drop this into your AI on a site that already has WPVibe:

Run the “Add Photos to a NextGEN Gallery with AI” recipe from the WPVibe cookbook on my connected site.

A gallery is never finished: new projects, this season’s menu, last weekend’s event. Adding photos means opening the gallery, importing from the media library and checking which ones are already in it, so galleries go stale.

Tell the AI which gallery and which photos. It shows you what the gallery holds now and where it is shown, searches your media library for the new photos, and marks the ones that may already be in it, because NextGEN imports a second copy of a photo sent twice. It adds what you pick, writes proper alt text for new photos that came in without any, saved after your yes, and reads the gallery back.

A change to a NextGEN gallery can’t be saved as a draft first: on a published page, visitors see the new photos as soon as they are added, so the AI asks first. New photos go at the end. The abilities can’t take photos out or change their order: to undo, remove them in the gallery’s edit screen. To start a new gallery, use this recipe.

Outcome

The gallery holds the photos you added, with alt text, after every photo it had before, and you know where it is shown.