Skip to content

Instantly share code, notes, and snippets.

@mergeweb
Created January 29, 2013 18:25
Show Gist options
  • Save mergeweb/4666385 to your computer and use it in GitHub Desktop.
Save mergeweb/4666385 to your computer and use it in GitHub Desktop.
Replace the default gallery with a simple thickbox
add_action('init', 'load_classes');
/**
* Function Name: load_classes
* Description: Load the classes we need
* Date Added: Thu, Jan 24, 2013
*/
function load_classes(){
global $GalleryHelper;
$GalleryHelper = new GalleryHelper();
}
class GalleryHelper{
function __construct(){
// Remove the default wordpress shortcode
remove_shortcode('gallery', 'gallery_shortcode');
// Add our new gallery
add_shortcode('gallery', array($this, 'gallery'));
}
/**
* Function Name: gallery
* Description: Replace the default wordpress gallery with our own
* Date Added: Mon, Jan 28, 2013
*/
public function gallery($attr){
$gallery_id = time();
$ids = explode(',',$attr['ids']);
foreach($ids as $id){
echo '<a rel="gallery-'.$gallery_id.'" href="'. array_shift(wp_get_attachment_image_src($id, 'large')).'" class="thickbox">'.wp_get_attachment_image($id, 'accommodation').'</a>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment