Title: Changing gallery code. Is it possible?
Last modified: August 21, 2016

---

# Changing gallery code. Is it possible?

 *  [richardcz](https://wordpress.org/support/users/richardcz/)
 * (@richardcz)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/changing-gallery-code-is-it-possible/)
 * I have made my own theme and I let wordpress generate its gallery. Now, I get
   something like this:
 *     ```
       <dl class='gallery-item'>
       			<dt class='gallery-icon landscape'>
       				<img width="1200" height="789" src="http://*****.com/wp-content/uploads/2013/08/61-1200x789.jpg" class="attachment-large" alt="6" />
       			</dt></dl>
       ```
   
 * My forst question is, can I change this codea that wordpress generates? If so,
   where? It would be great if I could change it without any plugin. I would like
   to use the width and add it to styles. It would need to result it into this:
 *     ```
       <dl class='gallery-item'>
       			<dt class='gallery-icon landscape'>
       				<img width="1200" height="789" src="http://*****.com/wp-content/uploads/2013/08/61-1200x789.jpg" class="attachment-large" alt="6" style="max-width:1200px"/>
       			</dt></dl>
       ```
   
 * Any suggestions where to change the gallery code?

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

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [12 years, 9 months ago](https://wordpress.org/support/topic/changing-gallery-code-is-it-possible/#post-4034843)
 * You want to add `style="max-width:1200px"` to the `<img` tag? Have you considered
   just applying that to the existing CSS tags? That may be easier than using a 
   filter to add that `class` tag.
 * If you can provide a link to a gallery then I could suggest the specific CSS.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/changing-gallery-code-is-it-possible/#post-4034875)
 * generally, you can code your own gallery code;
    add this to functions.php of 
   your theme:
 *     ```
       remove_shortcode('gallery','gallery_shortcode');
       add_shortcode('gallery','custom_gallery_shortcode');
   
       function custom_gallery_shortcode( $attr ) {
       //your gallery code here//
       }
       ```
   
 * for reference, the native gallery shortcode is in /wp-includes/media.php from
   line 659
 *  [gusaroo](https://wordpress.org/support/users/gusaroo/)
 * (@gusaroo)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/changing-gallery-code-is-it-possible/#post-4035073)
 * I’m having a similar issue here;
    [http://dev.chalkhillresidency.com/](http://dev.chalkhillresidency.com/)
   user: [ redacted ] password: [ redacted ] I want the gallery as a whole to align
   left, but the image area seems to be defaulting to landscape.
 * Any help would be much appreciated!
    Lee

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

The topic ‘Changing gallery code. Is it possible?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 4 participants
 * Last reply from: [gusaroo](https://wordpress.org/support/users/gusaroo/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/changing-gallery-code-is-it-possible/#post-4035073)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
