/ Published in: PHP
This is a combination of two fixes from Michael at [WPEngineer.com](http://wpengineer.com/a-solution-for-the-wordpress-gallery "WPEngineer.com"), which removes the styles from the gallery output, and a follow-up comment by [Aaron Cimolini](http://wpengineer.com/a-solution-for-the-wordpress-gallery/#comment-2070), which allows the developer to omit shortcode attributes.
The blog stripped some of the usable code from the comment, so I cleaned it up and reposted it here. I'm using it with the Sandbox theme, so I've replaced the original sandbox_gallery function with Michael and Aaron's improvement.
The blog stripped some of the usable code from the comment, so I cleaned it up and reposted it here. I'm using it with the Sandbox theme, so I've replaced the original sandbox_gallery function with Michael and Aaron's improvement.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Registers our function to filter default gallery shortcode remove_shortcode('gallery'); add_shortcode('gallery', 'sandbox_gallery'); // Function to filter the default gallery shortcode function sandbox_gallery($attr) { global $post; static $instance = 0; $instance++; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) } 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '' ), $attr)); if ( 'RAND' == $order ) $orderby = 'none'; $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); foreach ( $_attachments as $key => $val ) { $attachments[$val->ID] = $_attachments[$key]; } $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } else { $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; return $output; } // check to see if tags have been set to false. If they are the defaults or have been set to a string value use that as the tag. if ($itemtag) $itemtag = tag_escape($itemtag); if ($captiontag) $captiontag = tag_escape($captiontag); if ($icontag) $icontag = tag_escape($icontag); $selector = "gallery-{$instance}"; $output = "<div id='$selector' class='gallery galleryid-{$id}'>\n"; $i = 0; foreach ( $attachments as $id => $attachment ) { ++$i; $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); if ($itemtag) { $output .= '<'.$itemtag.' class="gallery-item '; if( $columns > 0 && $i % $columns == 0 ) $output .= " last"; $output .= '">'; } if ($icontag) $output .= "\n\t<" .$icontag. ">\t"; $output .= "\n\t".$link; if ($icontag) $output .= "\n\t</".$icontag.">"; // if the attachment has a caption set if ($captiontag) $output .= "\n<" .$captiontag. ">\n\t"; $output .= wptexturize($attachment->post_excerpt); if ($captiontag) $output .= "\n</" .$captiontag. ">" . "<!-- end caption -->\n"; } if ($itemtag) $output .= "\n</".$itemtag ."><!-- end itemtag -->\n"; if ( $columns > 0 && $i % $columns == 0 ) $output .= "\n"; } $output .= "</div><!-- end gallery -->\n"; return $output; }
URL: http://368design.com