Title: Gallery shortcode inserts styles
Last modified: August 19, 2016

---

# Gallery shortcode inserts styles

 *  [pshoeg](https://wordpress.org/support/users/pshoeg/)
 * (@pshoeg)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/gallery-shortcode-inserts-styles/)
 * Hi there,
 * I’m trying to create a gallery with WordPress using the native gallery function.
   I don’t want to use any plugin, as the native gallery does all I want it to do.
   However, whenever I insert the shortcode (`[gallery]`), it also, right before
   the images, inserts this code:
 *     ```
       <style type='text/css'>
       			.gallery {
       				margin: auto;
       			}
       			.gallery-item {
       				float: left;
       				margin-top: 10px;
       				text-align: center;
       				width: 33%;			}
       			.gallery img {
       				border: 2px solid #cfcfcf;
       			}
       			.gallery-caption {
       				margin-left: 0;
       			}
       		</style>
       ```
   
 * I don’t want this code, as I’d like to style my own gallery! In the media.php
   file in wp-includes, I’ve tried to change the code for this, and nothing happens.

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/gallery-shortcode-inserts-styles/#post-1126980)
 * Try re-writing the gallery shortcode – without the CSS – within functions.php
   as `my_gallery_shortcode` and then add:
 *     ```
       remove_shortcode('gallery');
       add_shortcode('gallery', 'my_gallery_shortcode');
       ```
   
 * Just remember to add the relevant CSS to your stylesheet. I do this on all of
   my themes.
 *  [Webstractions](https://wordpress.org/support/users/webstractions/)
 * (@webstractions)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/gallery-shortcode-inserts-styles/#post-1127165)
 * You can also apply a filter to the gallery style without fiddling with any of
   the code.
 * Add this to your functions.php and remember to add the relevant CSS to your theme
   stylesheet:
 *     ```
       <br />
       <pre><code>add_filter( 'gallery_style', 'my_gallery_style', 99 );
   
       function my_gallery_style() {
           return "<div class='gallery'>";
       }
       ```
   
 * This will effectively obliterate all of the inline styles that the Gallery Shortcode
   injects into the Html. Even gets rid of the reference to media.php in the comment
   following the inline style.
 * The 99 argument in add_filter is to make sure that my_gallery_style is processed
   later in the queue.
 *  [Lokheed](https://wordpress.org/support/users/lokheed/)
 * (@lokheed)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/gallery-shortcode-inserts-styles/#post-1127215)
 * Webstractions,
 * Thanks for that! But it should be:
 *     ```
       add_filter( 'gallery_style', 'my_gallery_style', 99 );
   
       function my_gallery_style() {
           return "<div class='gallery'>";
       }
       ```
   
 *  [DDT](https://wordpress.org/support/users/ddt/)
 * (@ddt)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/gallery-shortcode-inserts-styles/#post-1127218)
 * hi there,
 * Is there anyway i could replace
    `<div class='gallery-item'>` with my own classes.
 * i am trying to get this
 *     ```
       <div class="grid_4 alpha center">
       	<div class="borderBoxNoPadding padding5">
       	[img]
       	</div>
       	</div>
       	<div class="grid_4  center">
       	<div class="borderBoxNoPadding padding5">
       	[img]
       	</div>
       	</div>
       	<div class="grid_4  center">
       	<div class="borderBoxNoPadding padding5">
       	[img]
       	</div>
       	</div>
       	<div class="grid_4  omega center">
       	<div class="borderBoxNoPadding padding5">
       	[img]
       	</div>
       	</div>
       ```
   
 * Notice the first div and last div have another class (alpha, omega)
 * Any tips??

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

The topic ‘Gallery shortcode inserts styles’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 5 participants
 * Last reply from: [DDT](https://wordpress.org/support/users/ddt/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/gallery-shortcode-inserts-styles/#post-1127218)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
