20 Feb 2009

Remove WordPress [gallery] shortcode embedded CSS

Dump this code anywhere in Theme’s template functions.php file (For example, functions.php file for a Theme named “default” would probably reside in the directory wp-content/themes/default/functions.php):

add_filter('gallery_style', 
	create_function(
		'$css', 
		'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
		)
	);

And these are the classes for your stylesheet:

.gallery {}
.gallery-item {}
.gallery-icon {}
.gallery-caption {}

Comments RSS feed

4 Comments

  1. Just like everyone else, this worked perfectly for me. I am interested in understanding why it works, though. Can anyone explain to me what’s going on in the create_function part? Not sure what what’s going on in the replace.

    Reply

  2. Thanks for this code!, works fine.

    Reply

  3. Thanks for the tip, works perfect!

    Reply

  4. I just need to find a way to get the rid of the inserted clear:both line breaks that works now.

    Reply

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>