I think it better, when you parse before triggered wp_head; maybe this one:
add_action('the_posts', 'cleaner_gallery_head', 0); function cleaner_gallery_head($posts) { if (empty($posts)) return $posts; $found = false; foreach ($posts as $post) { if (stripos($post->post_content, '[gallery')) $found = true; } if ($found) wp_enqueue_style( 'cleaner-gallery', CLEANER_GALLERY_URL . '/cleaner-gallery.css', false, 0.7, 'all' ); return $posts; }