WordPress.org

Ready to get started?Download WordPress

Forums

Gallery Shortcode options. (3 posts)

  1. minute44
    Member
    Posted 6 years ago #

    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

  2. Justin Tadlock
    Member
    Posted 6 years ago #

    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

  3. Edouard Duplessis
    Member
    Posted 5 years ago #

    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;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic