Title: gallery loop
Last modified: August 20, 2016

---

# gallery loop

 *  [charlcfc](https://wordpress.org/support/users/charlcfc/)
 * (@charlcfc)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/gallery-loop/)
 * Hi all
 * I’m using the standard WP gallery functionality & would like to modify the WP
   gallery loop to include the id of each attachment image.
 * Default:
 * <img width=”150″ height=”150″ title=”imagetitle” alt=”imagealt” class=”attachment-
   thumbnail” src=”source-to-image-jpg”>
 * Would like add the image id:
 * <img width=”150″ height=”150″ title=”imagetitle” alt=”imagealt” id=”#id” class
   =”attachment-thumbnail” src=”source-to-image-jpg”>
 * Is there a filter which a person can use for this or any other code to achieve
   this?
 * Regards

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/gallery-loop/#post-3445386)
 * WordPress uses [wp_get_attachment_link](http://codex.wordpress.org/Function_Reference/wp_get_attachment_link)
   to display the gallery images. You can filter that function to add the ID. Example:
 *     ```
       add_filter( 'wp_get_attachment_link', 'add_image_attribute_id',10,6);
       function add_image_attribute_id($markup, $id, $size, $permalink, $icon, $text ) {
   
       	$pos = strpos($markup, '<img ');
       	if ($pos !== false) {
       		return substr_replace($markup, '<img id="image-' . $id . '" ', $pos, strlen('<img '));
       	}
   
       	return $markup;
   
       }
       ```
   
 *  Thread Starter [charlcfc](https://wordpress.org/support/users/charlcfc/)
 * (@charlcfc)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/gallery-loop/#post-3445389)
 * Thank you very much keesiemeijer. That worked 100%! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘gallery loop’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [charlcfc](https://wordpress.org/support/users/charlcfc/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/gallery-loop/#post-3445389)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
