Created
February 28, 2012 15:09
-
-
Save roose/1933007 to your computer and use it in GitHub Desktop.
Exclude post thumbnail from wordpress native gallery
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
<?php | |
function exclude_thumbnail_from_gallery($null, $attr) | |
{ | |
if (!$thumbnail_ID = get_post_thumbnail_id()) | |
return $null; // no point carrying on if no thumbnail ID | |
// temporarily remove the filter, otherwise endless loop! | |
remove_filter('post_gallery', 'exclude_thumbnail_from_gallery'); | |
// pop in our excluded thumbnail | |
if (!isset($attr['exclude']) || empty($attr['exclude'])) | |
$attr['exclude'] = array($thumbnail_ID); | |
elseif (is_array($attr['exclude'])) | |
$attr['exclude'][] = $thumbnail_ID; | |
// now manually invoke the shortcode handler | |
$gallery = gallery_shortcode($attr); | |
// add the filter back | |
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2); | |
// return output to the calling instance of gallery_shortcode() | |
return $gallery; | |
} | |
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment