Skip to content

Instantly share code, notes, and snippets.

@dnlmzw
Created August 8, 2013 17:11
Show Gist options
  • Save dnlmzw/6186592 to your computer and use it in GitHub Desktop.
Save dnlmzw/6186592 to your computer and use it in GitHub Desktop.
// // ########################
// // ########################
// // ########################
// // ########################
// GALLERY SHORTCODE OVERWRITE
// Bind to header
add_action('wp_head', 'header_init');
// Remove default shortcode
remove_shortcode('gallery', 'gallery_shortcode');
// Add custom shortcode (blank)
add_shortcode('gallery', 'gallery_shortcode_overwrite');
// Header init
function header_init () {
global $post;
// // ########################
// GALLERY ARRAY JAVASCRIPT OUTPUT
// Split content into ID's
$ids = explode('[gallery ids="',$post->post_content);
$ids = explode('"]', $ids[1]); // Refactor? - could be done with regexp, and maybe even smarter
// Clean array to return
$imgs = array();
// Explode and loop through attr ID's
foreach (explode(',',$ids[0]) as $id) {
// Set caption of image
$caption = get_post_field('post_excerpt', $id);
// Set url of image
$url = wp_get_attachment_image_src($id);
// Push to array
array_push($imgs,
array(
'title' => $caption,
'image' => $url[0]
));
}
// Echo slideImages javascript variable
echo "\n" . '<script type="text/javascript">var slideImages = ' . json_encode($imgs) . ';</script>';
// // END ####################
// // ########################
}
function gallery_shortcode_overwrite ($attr) {
return '';
}
// // ########################
// // ########################
// // ########################
// // ########################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment