[wp-hackers] WP 2.5 gallery breaking xhtml 1.0

Andrew Ozz admin at laptoptips.ca
Fri Jun 20 11:24:35 GMT 2008


Javier Aroche wrote:
> Even better, an hook that themes should remove ;)

I actually don't understand this whole thread. In trunk we have support 
for wp_register_style(), wp_deregister_style(), wp_enqueue_style(), etc. 
working exactly the same way as the similar js functions. Why not use 
them? Something like this should work well:

function register_gallery_css() {
   $url = WP_CONTENT_URL.'/themes/default/gallery.css';
   wp_register_style( 'gallery', $url, array(), '20080619', 'screen' );
}
add_action('init', 'register_gallery_css', 5);

function print_gallery_css() {
   global $wp_styles;
	
   if ( isset($wp_styles) && $wp_styles->query('gallery') )
     wp_print_styles('gallery');
}
add_action('wp_head', 'print_gallery_css');

The gallery.css can be added to the default theme or other appropriate 
place.

Then the themes that have styles for the gallery can do this in the 
functions.php:

function no_gallery_css() {
   wp_deregister_style( 'gallery' );
}
add_action('init', 'no_gallery_css');

Even plugins that want to replace the default gallery.css but only for 
themes that don't have styles for it can do this:

function plugin_gallery_css() {
   $url = ...
   wp_register_style( 'gallery', $url, array(), 'ver', 'screen' );
}
add_action('init', 'plugin_gallery_css', 4);

(it won't be registered second time if the handle already exists).

Also we may need to do something similar for the .alignleft, 
.alignright, .aligncenter css classes too.


More information about the wp-hackers mailing list