Jan 21, 2013

Remove the default Gallery Style in WordPress

We want to customize a lot of things in our WordPress themes, and WordPress gallery style can be one of those. At first, it looks like to throw some CSS code in the style.css and it’s done. But that alone, is not gonna work since WordPress automatically adds a default style snippet in the post containing the gallery, and this overrides all of your CSS code coming from style.css or anywhere else.

[caption id=“attachment_275” align=“alignnone” width=“640”]Dandelion WordPress Theme GalleryExample of Custom Gallery on Dandelion WordPress Theme[/caption]

So, the hurdle in our way to customize our gallery look is that automatically added style snippet. Once we restrict the addition of this default style, we are almost done.

So, what else I need to do to get this done? Well, this can be accomplished by telling WordPress not to add that style code segment in the post containing a gallery. We can do that by adding the below hook in functions.php of our WordPress theme: add_filter( 'use_default_gallery_style', '__return_false' );

Now, save the functions.php file and add your custom styles to style.css and test a gallery. Bang! Your custom WordPress gallery styles are now working!

Rahul C.

Rahul C. is a web developer running W3Bits since 2012. He loves making things on the internet and sharing his extensive knowledge about front-end web development.

Want to stay up to date?

Sign up for our email newsletter.

Only the relevant, to-the-point content. Zero spam.