• Okay,

    I’m absolutely itching to use the new gallery shortcode feature in 2.5 but I haven’t yet because I do not wish to compromise the integrity of my markup.

    At the moment my site validates as XHTML 1.0 Strict and I’m serious about web standards and best practices. The gallery shortcode feature is, in theory, a phenominal addition to WordPress with one exception; The code it inserts forces you to use inline styles.

    Not only does this go aginst the golden rule of seperation of content and style, it causes my markup to lose it’s validity as style isn’t allowed to be used in this way in the strict doctype.

    My question is: How , if at all, can I stop the shortcode inserting in-line styles so I can use my global stylesheet to format my galleries?

    thanks

    Dan

Viewing 2 replies - 1 through 2 (of 2 total)
  • I wrote a plugin to handle the invalid XHTML and style it inserts into the page. It’s still in beta but should work:
    Cleaner gallery plugin

    I’ve modify the gallery shortcode to do a better and a cleaner job

    here’s the code
    wp-includes/media.php line 384

    function gallery_shortcode($attr) {
    	global $post;
    
    	// Allow plugins/themes to override the default gallery template.
    	$output = apply_filters('post_gallery', '', $attr);
    	if ( $output != '' )
    		return $output;
    
    	// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    	if ( isset( $attr['orderby'] ) ) {
    		$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    		if ( !$attr['orderby'] )
    			unset( $attr['orderby'] );
    	}
    
    	extract(shortcode_atts(array(
    		'order'      => 'ASC',
    		'orderby'    => 'menu_order ID',
    		'id'         => $post->ID,
    		'itemtag'    => '',
    		'icontag'    => '',
    		'captiontag' => '',
    		'columns'    => 4,
    		'size'       => 'thumbnail',
    	), $attr));
    
    	$id = intval($id);
    	$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    
    	if ( empty($attachments) )
    		return '';
    
    	if ( is_feed() ) {
    		$output = "\n";
    		foreach ( $attachments as $id => $attachment )
    			$output .= wp_get_attachment_link($id, $size, true) . "\n";
    		return $output;
    	}
    
    	$listtag = tag_escape($listtag);
    	$itemtag = tag_escape($itemtag);
    	$captiontag = tag_escape($captiontag);
    	$columns = intval($columns);
    	$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
    
    	foreach ( $attachments as $id => $attachment ) {
    		$link = wp_get_attachment_image($id, $size, true);
    		$output .= '<a href="'.wp_get_attachment_url($id).'">'.$link.'</a>';
    	}
    
    	$output .= "<br style='clear: both;' />";
    
    	return $output;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Gallery Shortcode options.’ is closed to new replies.