Created
June 20, 2013 08:36
-
-
Save djave-co/5821180 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove the shortcode function that is already there | |
remove_shortcode('gallery'); | |
// Add our new one | |
add_shortcode('gallery', 'djave_gallery_shortcode'); | |
// Define the new gallery function | |
function djave_gallery_shortcode($atts) { | |
// Define some variables | |
global $post; | |
$retour; | |
// Grab the shortcode atts - the important one here is 'ids' | |
// Also, set a default image size | |
extract(shortcode_atts(array( | |
'id' => $post->ID, | |
'ids' => "", | |
'image_size' => 'medium', | |
), $atts)); | |
// Turn the ids into an array we can loop over | |
$image_ids = explode(",", $ids); | |
// Loop over the array | |
foreach($image_ids as $image_id): | |
// Grab each image attachment | |
$img = wp_get_attachment_image($image_id, $image_size, false); | |
// Add it to the return data | |
$retour .= $img; | |
endforeach; | |
// Return that data! | |
return $retour; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment