Title: Gallery Functions
Last modified: August 20, 2016

---

# Gallery Functions

 *  [rio38](https://wordpress.org/support/users/rio38/)
 * (@rio38)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/gallery-functions/)
 * I am using the Gallery shortcode in my posts but would like to insert google 
   adsense after a specified number of images within the gallery.
 * Could someone tell me where the actual code is for the Gallery so I can modify
   it accordingly?

Viewing 1 replies (of 1 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/gallery-functions/#post-2152424)
 * in /wp-includes/media.php from line 745
 * to do it without hacking core files:
 * add this to functions.php of your theme:
 *     ```
       remove_shortcode('gallery', 'gallery_shortcode');
       add_shortcode('gallery', 'ad_gallery_shortcode');
       function ad_gallery_shortcode($attr) {
       /*...
       the full code from media.php -
       until line 876, last few lines see below;
       ...*/
       $output .= "
       			<br style='clear: both;' />
       		</div>\n";
   
       	return $output;
       }
       ```
   
 * then edit it there to include your ads.

Viewing 1 replies (of 1 total)

The topic ‘Gallery Functions’ is closed to new replies.

## Tags

 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/gallery-functions/#post-2152424)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
