---
title: Smarter Cleaner Gallery
date: 2010-01-13T16:23:53+00:00
modified: 2015-11-19T14:05:14+00:00
permalink: https://kaspars.net/blog/smarter-cleaner-gallery
post_type: post
author:
  name: Kaspars
  avatar: https://reverse.kaspars.net/gravatar/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=mm&r=g
post_tag:
  - Plugin
category:
  - WordPress
---

# Smarter Cleaner Gallery

Justin Tadlock’s [Cleaner Gallery](http://justintadlock.com/archives/2008/04/13/cleaner-wordpress-gallery-plugin "Cleaner gallery plugin for WordPress") plugin fixes the semantics of the WordPress built-in gallery feature by placing all of the gallery related CSS in an external file instead of the inline CSS produced by WordPress core.

However, the problem is that this CSS file is loaded on every page request. Therefore, until WordPress supports combining all CSS files into one, here is a quick way to hide this CSS file on all pages that don’t contain a gallery (line 128 of `cleaner-gallery.php`):

**Note**: this will add `cleaner-gallery.css` only on single post and page views (not indexes or archives).

```
add_action('wp_head', 'cleaner_gallery_head', 0);
function cleaner_gallery_head() {
	global $post;
	if ( strstr( $post->post_content, '[gallery' ) )
		wp_enqueue_style( 'cleaner-gallery', CLEANER_GALLERY_URL . '/cleaner-gallery.css', false, 0.7, 'all' );
}
```

Hopefully, Justin can incorporate this into the next release of this handy plugin.